Gorilla3D Primative Teachings

Joseph Says: STOP SPAMMING MY %$#@ING SITE $%#@!!!!!
Search

Gorilla Db - (Improved) MySQLi Wrapper


Sunday, August 3, 2008

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 Labs

  1.  
  2. //-- Prepared Statements
  3. // Execute a query
  4. $db->prepare('SELECT * FROM blog_entries WHERE id=?')->bind(23)->query();
  5. // or
  6. $db->prepare(SELECT * FROM blog_entries WHERE id=?);
  7. $db->bind(23);
  8. $db->query();
  9. // you can also stack binds
  10. $db->prepare('SELECT * FROM blog_entries WHERE id=? and title=?')
  11. ->bind(23)->bind('Hello World')->query();
  12. $db->prepare('SELECT * FROM blog_entries WHERE id=? and title=?')
  13. ->bind(array(23,'Hello World'))->query();
  14. $entry = $db->fetchOne();
  15.  
  16. // you can do can use them all in the same parameter
  17. $db->prepare('SELECT * FROM events WHERE name LIKE ? OR name LIKE ? and location LIKE ?')
  18. ->bind('%My%', '%Event%', '%San%')
  19. ->query();
  20.  
  21. // you can do can use an array and if they have keys you can assign you ?'s to them
  22. $db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg2 and location LIKE ?')
  23. ->bind(array('arg2'=>'%Event%'), '%San%', array('arg1'=>'%My%'))
  24. ->query();
  25.  
  26. // a cleaner example notice they can be in any order but you probably shouldn't
  27. $db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg2 and location LIKE ?')
  28. ->bind(array('arg2'=>'%Event%', '%San%', 'arg1'=>'%My%'))
  29. ->query();
  30.  
  31. // and yes keys can be used multiple times
  32. $db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg1 and location LIKE ?')
  33. ->bind(array('%San%', 'arg1'=>'%My%'))
  34. ->query();
  35.  

Comments


pcdinh posted 33 days ago

http://labs.gorilla3d.com/ is dead

Moreover, the page http://gorilla3d.com/gorilla_labs contains no information about this package


Add Comment