I've updated my mysqli wrapper to handle binds better and easier to new people trying to use prepared statements. I've also added Non-Filtered binds, because I'll also be release my Table class to help with simple queries you always end up running. Db is a connection manager, it will use the connection you first create throughout your application. You can continue to call Db:init() and as long as a connection has already been made, you can run queries. Best of all It has prepared statements thanks to Wrapping MySQLi. For documentation and download please visit Gorilla Docs
//-- Prepared Statements
// Execute a query
$db->prepare('SELECT * FROM blog_entries WHERE id=?')->bind(23)->query();
// or
$db->prepare(SELECT * FROM blog_entries WHERE id=?);
$db->bind(23);
$db->query();
// you can also stack binds
$db->prepare('SELECT * FROM blog_entries WHERE id=? and title=?')
->bind(23)->bind('Hello World')->query();
$db->prepare('SELECT * FROM blog_entries WHERE id=? and title=?')
->bind(array(23,'Hello World'))->query();
$entry = $db->fetchOne();
// you can do can use them all in the same parameter
$db->prepare('SELECT * FROM events WHERE name LIKE ? OR name LIKE ? and location LIKE ?')
->bind('%My%', '%Event%', '%San%')
->query();
// you can do can use an array and if they have keys you can assign you ?'s to them
$db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg2 and location LIKE ?')
->bind(array('arg2'=>'%Event%'), '%San%', array('arg1'=>'%My%'))
->query();
// a cleaner example notice they can be in any order but you probably shouldn't
$db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg2 and location LIKE ?')
->bind(array('arg2'=>'%Event%', '%San%', 'arg1'=>'%My%'))
->query();
// and yes keys can be used multiple times
$db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg1 and location LIKE ?')
->bind(array('%San%', 'arg1'=>'%My%'))
->query();
« Back to my notebook