Code Monkey home page Code Monkey logo

shortcurd's Introduction

shortcurd

Simple CURD with PHP and MySQL in OOP based. Very simple and short code for project setup. Also many methods are available for the project setup and other functions.

File Structure :

  1. config.php : Configuration for the script
  2. database.php : Database for the test
  3. user.php : Example script with Add, Edit, Records Display, Delete, Active/Inactive Change Status and Pagination methods
  4. class/Main.class.php : Class file for all the important methods

Methods in the Class :

  1. RedirectPage($url) : Parameter(s) : 1 : url (string) => The file name or the url where you want to redirect the user Details : The method will redirect to the give url. Example : $Main->RedirectPage("userdetails.php");

===========================

  1. ViewLink($id) : Details : The method will generate VIEW action like user.php?action=view&id=1. You just need to provide the PRIMARY KEY/ID of the record which you want to display. Parameter(s) : 1 : id (integer) => The primary key for the record which you want to get details. Example : View Details Output : user.php?action=view&id=1

===========================

  1. EditLink($id) : Details : The method will generate EDIT action like user.php?action=edit&id=1. You just need to provide the PRIMARY KEY/ID of the record which you want to edi the record. Parameter(s) : 1 : id (integer)=> The primary key for the record which you want to get and edit details. Example : Edit Output : user.php?action=edit&id=1

===========================

  1. StatusChangeLink($id,$currentstatus) : Details : The method will generate STATUS CHANGE action like user.php?action=action&id=1&status=0. You just need to provide the PRIMARY KEY/ID of the record which you want to change the active/inactive status of the record. This method will generate two links for the record. One for Active Status and onther for Inactive Status Parameter(s) : 1 : id (integer)=> The primary key for the record which you want to change the status. 2 : current status (integer) => if you have set with 0 as inactive and 1 as active status. You need to pass the current status of the record. Example : StatusChangeLink(1,0); ?> Output : 1 : Active : If the record has active status, this link will be used to inactive the same. 2 : Inactive : If the record has inactive status, this link will be used to active the same.

===========================

  1. StatusLink($id,$status) : Details : The method will generate STATUS action like user.php?action=status&id=1&status=0. You just need to provide the PRIMARY KEY/ID of the record which you want to edi the record. Parameter(s) : 1 : id (integer)=> The primary key for the record which you want to change the status. 2 : status (integer) => status which you want to change Example : Change to Inactive Output : user.php?action=status&id=1&status=0

===========================

  1. DeleteLink($id) : Details : The method will generate DELETE action like user.php?action=delete&id=1. You just need to provide the PRIMARY KEY/ID of the record which you want to edi the record. Parameter(s) : 1 : id (integer)=> The primary key for the record which you want to delete Example : Edit Output : user.php?action=delete&id=1

===========================

  1. SendMail($mailto,$subject,$message,$attachments="") : Details : The method will send mail using PHP mail() function. you can also change it with SMTP. Parameter(s) : 1 : $mailto (string)=> Email Address to send the mail 2 : $subject (string)=> Subject for the mail 3 : $message (string)=> Message for the Mail. 4 : $attachments (string)=> Attachment for the Mail. If you want to attach any file, provide the file path for the same. Example :
SendMail($mailto,$subject,$message,$attachments=""); ?>

===========================

  1. GetRandomString($length,$type=0) Details : The method will generate the randon string which you can use for verification code or any other. Parameter(s) : 1 : $length (integer)=> String Length which you want. 2 : $type (integer)=> 0 for alpha-numeric, 1 for numberic only and 2 for alpha only. By Default 0 will be set.

Example :

GetRandomString(10) ?> => AK76D2s9mh GetRandomString(4,1) ?> => 8169 GetRandomString(5,2) ?> => mdiwl

===========================

  1. InsertRecord($tablename, array $values) Details : The method will insert record to given table name. You just need to provide the table name and the array with fields and value. This will return the Last Insert Id for the record. The fields which are given, will be added only.

Parameter(s) : 1 : $tablename (string) : "user_master". Please note that if you have already set the TABLE_PREFIX in the config.php file, you need not to add that prefix here. 2 : $array (array)=> array("field1"=>"value1", "field2"=>"value2");

Example :

"bharat383","password"=>$password,"email"=>"[email protected]"); $insert_id = $Main->InsertRecord("user_master", $info_array); ?>

Output : Last insert id for the record.

===========================

  1. InsertMultipleRecord($tablename,$fieldarray,$valuearray) Details : The method will insert multiple records to given table name. You just need to provide the table name and the array of fields name and array values. This will return the number of records added to the table. The fields which are given, will be added only.

Parameter(s) : 1 : $tablename (string) : "user_master". Please note that if you have already set the TABLE_PREFIX in the config.php file, you need not to add that prefix here. 2 : $fieldarray (array)=> array("field1", "field2"); 3 : $valuearray (array)=> array( [0]=>array("value1", "value2"), [1]=>array("value11", "value12"), [2]=>array("value21", "value22"), [3]=>array("value31", "value32") );

Example :

array( [0]=>array("test1", "123456", "[email protected]"), [1]=>array("test2", "123456", "[email protected]"), [2]=>array("test3", "123456", "[email protected]"), [3]=>array("test4", "123546", "[email protected]") ); $total = InsertMultipleRecord("user_master",$fieldarray,$valuearray); ?>

Output : Number of records addd with this method.

===========================

  1. GetSingleRecord($tablename,array $array) Details : The method will return the details of the single record in the array format as per your 2nd parameter.

Parameter(s) : 1 : $tablename (string) : "user_master". Please note that if you have already set the TABLE_PREFIX in the config.php file, you need not to add that prefix here. 2 : $array (array) : 2.1 fields => Fields which you want to retrive. If you want to retrive all fields value, just leave it blank or use "" for the same. By default it will take "" for the same. 2.2 where : where condition of you query in simple plain text like "user_id=1 and active_status=1". Do not use "where" here.

Example :

"user_id=1"); $userdata = $Main->GetSingleRecord("user_master",$info_array); ?>

Return : Array => array("username"=>"bharat383","password"="12345","email"=>"[email protected]","active_status"="1")

===========================

  1. GetRecord($tablename,array $array) Details : The method will return the details of the records in the array format as per your 2nd parameter.

Parameter(s) : 1 : $tablename (string) : "user_master". Please note that if you have already set the TABLE_PREFIX in the config.php file, you need not to add that prefix here. 2 : $array (array) : 2.1 fields => Fields which you want to retrive. If you want to retrive all fields value, just leave it blank or use "" for the same. By default it will take "" for the same. 2.2 where (string) : where condition of you query in simple plain text like "user_id=1 and active_status=1". Do not use "where" here. 2.3 orderby (string) : order by field name 2.4 ordertype (string) : order type (asc or desc) 2.5 limit (integer) : number of records 2.6 startfrom (string) : start number of record 2.7 groupby (string) : group by field name

Example :

"active_status=1"); $userdata = $Main->GetRecord("user_master",$info_array); ?>

Return : Array => array( [0]=>array("username"=>"bharat383","password"="12345","email"=>"[email protected]","active_status"="1"), [1]=>array("username"=>"test1","password"="12345","email"=>"[email protected]","active_status"="1") [2]=>array("username"=>"test2","password"="12345","email"=>"[email protected]","active_status"="1") );

  1. PagiNation($tablename,$primarykey) Details : The method will display the pagination button/link

Parameter(s) : 1 : $tablename (string) : "user_master". Please note that if you have already set the TABLE_PREFIX in the config.php file, you need not to add that prefix here. 2 : $primarykey (string) : primary key which can be count.

Example :

Pagination("user_master","user_id"); ?>

===========================

  1. UpdateRecord($tablename,array $array, $where="") Details : The method will update the records. Parameter(s) : 1 : $tablename (string) : "user_master". Please note that if you have already set the TABLE_PREFIX in the config.php file, you need not to add that prefix here. 2 : $array (array)=> array("field1"=>"value1", "field2"=>"value2"); 3 : $where (string) : where conditions

Example :

UpdateRecord("user_master",$array, $where="user_id='1'"); ?>

Return/Output : This method will return you the number of updated records.

===========================

  1. DeleteRecord($tablename,$where="",$limit=0) Details : The method will delete the records from the table. Parameter(s) : 1 : $tablename (string) : "user_master". Please note that if you have already set the TABLE_PREFIX in the config.php file, you need not to add that prefix here. 2 : $where (string) : where conditions 3 : $limit (integer) : number of records to be delete.

Example :

DeleteRecord("user_master",$where="user_id='1'"); ?>

Return/Output : This method will return you the number of deleted records.

===========================

  1. GetCustom($query_string) Details : The method will return array as per your query. You can define here any custom, join query. Parameter(s) : 1 : $query_string (string) : MySQL query string.

Example :

GetCustom("select * from hm_user_master"); ?>

Return/Output : This method will return you the number of records in array.

===========================

  1. UploadFile($files,array $array) Details : The method will upload the file/files which you want to upload Parameter(s) : 1 $files (array) : $_FILES which has been used for the upload file. 2 $array : your upload file settings 2.1 uploadpath (string) : upload directory path 2.2 filetype (array) : file types array which you want to allow. 2.3 maxsize (integer) : file size to max size

Example :

UploadFile($_FILES['profile_picture'],$array); ?>

Return/Output : This method will return files name which has been uploaded. It will rename the file name.

===========================

  1. DeleteFile(array $array) Details : The method will upload the file/files which you want to upload Parameter(s) : 1 $array : your file settings 1.1 $files (array) : file name which you want to remove. You can remove multiple files. 1.2 uploadpath (string) : directory path from where you want to delete the file

Example :

DeleteFile($array); ?>

Return/Output : This method will return number of deleted file.

===========================

  1. DateDifference($date1,$date2) Details : The method will return you the array of two dates difference in hours and days Parameter(s) : 1 $date1 : First Date 1 $date2 : Second Date

Example :

DateDifference("2015-09-21 12:30:00","2015-09-25 19:00:00"); ?>

Return/Output : This method will return hours and days difference.

===========================

shortcurd's People

Contributors

bharat383 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.