MySQL Wrapper

This is a very lightweight, one file, one class MySQL Wrapper, simplifying datatbase management.

Getting started

  • Pull the source, include it in your project.
  • Create a \dadasign\utils\DB instance, passing a mysql resource to the constructor.
  • For selecting use get_where, get_row_where, get_product_where, get_single_product_where
  • For updates update, update_or_insert
  • For inserts insert

Basic Examples

Insert a row to the users table.

$db->insert('users', array('name'=>'Mike', 'age'=>45));

Select a row from users table where id is 5 and return an array with 'name' and 'age' fields

$db->get_row_where('users',array('name','age'), array('id'=>5));

Update age field in the users table where id is5.

$db->update('users', array('age'=>46),array('id'=>5));

Delete users table rows where id is 5.

$db->delete('users', array('id'=>5));

Count rows from users table where age field equals 24.

$db->count_rows_where('users', array('age'=>24));

Other features

  • Escapes strigns
  • Use query, query_row, query_results for advanced custom queries.
  • map_to for fetching key=>value results.
  • get_product_where and get_single_product_where accepts a function closure which allows returning a custom result instead of an associative array.
  • insert_id to get last inserted id
  • truncate and copy_table

Comes with no guarantees - use at your own risk.