Skip to content

Latest commit

 

History

History
81 lines (65 loc) · 1.48 KB

readme.md

File metadata and controls

81 lines (65 loc) · 1.48 KB

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