Mysql Done Right 0.24

A PHP class for MySQLi utilizing prepared queries

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!

What's new in Mysql Done Right 0.24:

  • The license has been changed to LGPL and the documentation was updated.
Read full changelog
send us
an update
LGPL (GNU Lesser General Public License) 
Daren Schwenke
ROOT \ Internet \ HTTP (WWW)
Mysql Done Right is a PHP5.0+ class which provides a SAFE, clean, object oriented, and efficient way to do MySQL database development.

All queries except those with multiple row results return exactly what you need in ONE LINE OF CODE.

This is all done while still maintaining use of prepared queries and bound parameters to eliminate the risk of SQL injection attacks and operate more efficiently.

No extra coding is needed on your part to reuse prepared queries. You simply write the same query again, and if you have done that one before, the prepared handle is reused. The newly bound parameters are used against the existing prepared handle, and the results are recomputed. The results themselves are not cached.

So there you have it. Simple use of prepared queries with bound parameters, while still having access to the fetch_object and fetch_assoc methods. Now you have no excuse.


See examples.php for database connection setup details.

General format for all queries:

 $db->method_name('MySQL query with ? substituted for variables','corresponding placeholder types',corresponding variables for placeholders);

That format explained:

SQL queries themselves are beyond the scope of this document.  Common examples are below.

Placeholders are allowed to be these types.  Straight from
  i      corresponding variable has type integer
  d     corresponding variable has type double
  s     corresponding variable has type string
  b     corresponding variable is a blob and will be sent in packets
  Sending data of type blob or text is currently limited to the size of max_allowed_packet.

Variables to assign to each type.  Should be scalars.


Inserts return insert ID:
$insert_id = $db->pinsert('INSERT INTO sometable (somestring,someint,somedouble,someblob) VALUES (?,?,?,?)','sidb',$string,$int,$double,$blob);

Updates return count of rows affected:
$rows_affected = $db->pexecute('UPDATE sometable SET somestring = ? WHERE someint = ? LIMIT 1','si',$string,$int);

Deletes return count of rows affected:
$rows_affected = $db->pexecute('DELETE FROM sometable WHERE someint = ? LIMIT 1','i',$int);

Just count rows return without reading the data:
$row_returned = $db->prows('SELECT something FROM sometable WHERE somestring = ? AND someint >= ?', 'si' , $string,$int );

Select a single row and return an object containing the data.
$obj = $db->psingle('SELECT someint,somestring FROM sometable WHERE someint = ? LIMIT 1','i',$int);
print $obj->someint; print $obj->somestring;

Select multiple rows and return a handle.
$some_sth = $db->pbind('SELECT somestring FROM sometable WHERE someint = ?','i',$int);
while ( $row = $some_sth->fetch_object() ) { print $row->somestring; }

Last updated on October 20th, 2009


#database development #MySQL development #PHP class #MySQL #database #development #PHP

Add your review!