The library is a Wrapper, so a class that calls a main class. Its' purpose is simplifying the handling and creating queries for the database, automating a lot of functions. A list of available methods and their descriptions below.
Basic methods for most queries
$result = $db->pdoQuery('SELECT * FROM users WHERE user_id = ?', ['1'])->result();
Note: It's important to point out that the result() method at the end returns the first row of the table. To receive all rows, you should use results() instead of result()
$results = $db->pdoQuery('SELECT * FROM users')->results();
A method that's used for collection
$select = $pdo->select('users')->results();
You can use it for simpler queries with defined data and filters
// Collects all rows
$select = $pdo->select('users', '*')->results();
// Collects rows from the given columns
$select = $pdo->select('users', ['user_id', 'user_name'])->results();
A method that's use only for adding data to the database
$dataArray = ['user_name' => 'Jack'];
$insert = $db->insert('users', $dataArray)->getLastInsertId();
Works on a similar basis as insert(), but it gives us the means to add multiple items
$dataArray = [];
$dataArray[] = ['user_name' => 'Eli'];
$dataArray[] = ['user_name' => 'Jack'];
$dataArray[] = ['user_name' => 'Mati'];
$insert = $db->insertBatch('users', $dataArray)->getAllLastInsertId();
The most convenient method for updating data in the whole wrapper
$dataArray = ['user_name' => 'Monana', 'user_age' => '35'];
$where = ['id' => 23];
$update = $db->update('users', $dataArray, $where)->affectedRows();
delete is used for deleting simple data
$where = ['age' => 35];
$delete = $db->delete('test', $where)->affectedRows();
In case of deleting more complicated data, related to greater/lesser/similar we use pdoQuery with recommendation of using whereChunkString.
Clears table
$truncate = $db->truncate('users');
Deletes table
$drop = $db->drop('users');
Shows a list of columns in the database, along with their types
$describe = $db->describe('users');
Counts the number of rows in the simpler queries
$count = $db->count('employees');
$bindWhere = ['user_name' => 'Jack'];
$count = $db->count('users', $bindWhere);
showQuery is a very useful method with big queries: thanks to it, instead of the result()/results() parameter, we use showQuery(), which shows us the Query with the basic variables.
$results = $db->pdoQuery('SELECT * FROM users')->showQuery();
echo $results;
Returns the last row id added
$getLastInsertId = $db->insert('users', $dataArray)->getLastInsertId();
echo $getLastInsertId;
Returns a table of all recently added ids for the insertBatch method.
Returns data in the default array format. Also available xml/json
$data = $db->results();
$data = $db->results('xml');
$data = $db->results('json');
The same principle as results, and, as previously mentioned, returns only the first row.
$data = $db->result();
$data = $db->result('xml');
$data = $db->result('json');
Returns the number of modified rows
$data = $db->affectedRows();
Start of the msql transaction
$data = $db->start();
End of the msql transaction
$data = $db->end();
REversing the changes in case of error during start/end
$data = $db->back();
Set to false by default during the configuration, it turns debug mode on/off
$db->setErrorLog(true); // true/false
Edit page (Query)