Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Pull request Compare This branch is 461 commits behind joshcam:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
MysqlDb.php
index.php
readme.md

readme.md

To utilize this class, first import MysqlDb.php into your project, and require it.


require_once('MysqlDb.php');

After that, create a new instance of the class.


$Db = new MysqlDb('host', 'username', 'password', 'databaseName');

Next, prepare your data, and call the necessary methods.

Insert Query


 'Inserted title',
    'body' => 'Inserted body'
);

if ( $Db->insert('posts', $insertData) ) echo 'success!';


Select Query


$results = $Db->get('tableName', 'numberOfRows-optional');
print_r($results); // contains array of returned rows

Update Query


$updateData = array(
   'fieldOne' => 'fieldValue',
    'fieldTwo' => 'fieldValue'
);
$Db->where('id', int);
$results = $Db->update('tableName', $updateData);

Delete Query


$Db->where('id', integer);
if ( $Db->delete('posts') ) echo 'successfully deleted'; 

Generic Query Method


$results = $Db->query('SELECT * from posts');
print_r($results); // contains array of returned rows

Where Method

This method allows you to specify the parameters of the query. For now, it only accepts one key => value pair.


$Db->where('id', int);
$results = $Db->get('tableName');
print_r($results); // contains array of returned rows