Skip to content

Oxicode/PHP-MySQLi-Database-Class

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Invocas a la clase

require_once('Mysqlidb.php');

Primero que nada establece los parametros de coneccion.

$db = new Mysqlidb('host', 'username', 'password', 'databaseName');

Ok, vamso a agregar data

Insert Query

$nuevo = array(
	'title' => 'Inserted title',
	'body' => 'Inserted body'
);

if($db->insert('posts', $nuevo)) echo 'ingreso!';

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', int);
if($db->delete('posts')) echo 'successfully deleted'; 

Generic Query Method

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

Raw Query Method

$params = array(3, 'My Title');
$resutls = $db->rawQuery("SELECT id, title, body FROM posts WHERE id = ? AND tile = ?", $params);
print_r($results); // contains array of returned rows

// will handle any SQL query

$params = array(10, 1, 10, 11, 2, 10);
$resutls = $db->rawQuery("(SELECT a FROM t1 WHERE a = ? AND B = ? ORDER BY a LIMIT ?) UNION(SELECT a FROM t2 WHERE a = ? AND B = ? ORDER BY a LIMIT ?)", $params);
print_r($results); // contains array of returned rows

Where Method

This method allows you to specify the parameters of the query.

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

Optionally you can use method chaining to call where multiple times without referencing your object over an over:

$results = $db
	->where('id', 1)
	->where('title', 'MyTitle')
	->get('tableName');

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%