CRUD
CRUD functions
CRUD functions
Create
// to insert new data to your DB, simply use:
$mb->addMBRecord($table,$data);
// where $table represent which table to insert your data into
// and $data is array of columns
// example:
$add['name']='John Doe';
$add['age']=42;
$add['register_date']=time();
$mb->addMBRecord('clients',$add);
// OR
$clientID = $mb->addMBRecord('clients',$add);
// it will return the last inserted id assigned to variable $clientID
Read ( Retrieve )
Read All Data
// you can fetch data from DB in different ways according to your needs
// if you want to fetch all data in a table
$data = $mb->getMBAllData($table, $cond, $printquery = 0);
// $data: the variable will hold your array in array data
// $table: from which table you want to fetch data
// $cond: the where clause, just add '1' to fetch ALL data, or add some conditions like 'age>40' or 'age=42 and gender="male"'
// you can always ignore the last command, or add 1 for debugging and print the sql query
Read a Single Row
// Call a single row data
$data = $mb->getMBDetails($table, $cond, $printquery = 0);
// $data: the variable will hold your array data
// $table: from which table you want to fetch data
// $cond: the where clause, you have to specify a conditions like 'id=3' or 'age=42 and gender="male"'
// it will return the first row meets the required conditions.
Read a Single ( or multiple non-ordered ) Fields
// call a single or multiple non-ordered fields from a row
$data = $mb->getMBTitle($table, $fields, $cond, $printquery = 0);
// $data: the variable will hold your array data
// $table: from which table you want to fetch data
// fields: string values e.g: 'age' OR 'age,gender'
// $cond: the where clause, you have to specify a conditions like 'id=3'
Update
// update existing data is very simple
$mb->updateMBRecord($table,$data,$cond);
// where $table represent in which table to edit your data
// and $data is array of columns to be updated, you don't have to include all table columns.
// and $cond specifies the where clause for this update query, example 'id=1'
$update['name']='John Doe';
$update['age']=42;
$mb->updateMBRecord('clients',$update,'id=1');
Delete
// delete any existing data
$mb->deleteMBRecord($table,$cond);
// where $table represent from which table you want to perform the deletion process
// and $cond specifies the where clause for this deletion query,
// example 'id=1'
$mb->deleteMBRecord('clients','id=1');
Last updated
Was this helpful?