Skip to content

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.

Notifications You must be signed in to change notification settings

freddymx/PHP-MySQL-Database-Class

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

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

About

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published