I've been meaning to write this for ages, might prove useful to someone. Bassicaly a mysql interface class for php It uses placeholders (?) for user data so that it can be escaped prior to feeding into mysql, so should hopefully be relativly secure http://code.q3f.org/class.mysql.phps Examples: PHP: require_once('class.mysql.php'); $db = new mysql(array( user => 'username', pass => 'password', db => 'database', ) ); $data = array( table => 'members', columns => array('username', 'password', 'id'), where => "username LIKE ?", order => '? asc', limit => '4,2', exec => array('%s', 'username'), ); print_r($db->select($data)); $data = array( table => 'announcements', columns => array('title', 'forum', 'announcement'), exec => array('test announcement', 1, 'lalalal'), ); print $db->insert($data) . " rows affected"; $data = array( table => 'announcements', set => array('title', 'forum'), where => 'id=?', exec => array('different test', '4' ,1), ); print $db->update($data) . " rows affected"; $data = array( table => 'announcements', ); print($db->delete($data) . " rows affected"; $data = array( query => 'select * from members order by ? asc limit 5', exec => array('username'), ); print_r($db->query($data)); $db->destroy(); Error handling is a little rough and ready ie the script dies if it encounters one Comments / criticisms / suggestions would be appreciated
Nice work, I also intended to write one of these classes so that custom error handling could be implemented on each query's execution while being editable from a single file. The only problem being that I would have to replace all the existing queries
I'm getting a "403: Forbidden" from your .phps file, any chance of that being sorted soon? This looks kind of cool. I've written a few of these for microsoft access, but now that I'm an open source hippie I haven't touched it in months. Have you thought of posting this on sourceforge or something similar, so people could provide updates? I see this as being a very cool tool, but I'd want to play with it and try to make a few enhancements, such as incorporating various types of joins. Looks cool though!
access databases need to be burnt on site. Now your an open source hippie thou, why not bring em to the masses, if you can make a standardized interface for MySQL MSSQL and MSACCESS that would be really narly! (failing that check C-omega, i don't know if its an ECMA standard yet, i belive there trying to make it, you can compile it with PHP via phlanger)
http://adodb.sourceforge.net/ Works with For PHP and Python. Available as include files in PHP, or pre-compiled C. teh speed!
Am half way round the world atm and am having problems with my hosting, will try and sort it when i get back