Databases: Bobo PHP DB Class
JImmy Bo (contact me)
This class simplifies connections to a MySQL database.
Connections are automatically created if they are not already connected on the first query (meaning a connect statement is not required).
The class can also retrieve the identifier of the last inserted record, and check whether a given table exists. A query can return data into an array, a single variable, or just return the id of the last insert (get,row,q respectively). Script can manually be told to open or close the connection (connect or close respectively).
More information on how to use this class is available in the class source code.
* example usage:
*
* 1) create a file called inc.config.php in it throw this:
* // include the class:
* include_once('class.db.php');
* // set the variables:
* $db_host = "localhost";
* $db_user = "myusername";
* $db_pass = "mypassword";
* $db_name = "mydatabasename";
* // make a db object:
* $db = new mydb($db_host, $db_user, $db_pass, $db_name);
*
* 2) now in your file that you want to access the db from just include_once('inc.config.php');
* don't worry it won't connect till it's first query and it does so automagically.
*
* 3) some example usage:
* // an insert
* $SQL = "INSERT INTO addressbook (name) VALUES ('bob')";
* $insertid = $db->q($SQL); // returns false if no insertid or the id
* echo $insertid;
*
* // a single row returned
* $SQL = "SELECT * FROM addressbook WHERE name LIKE 'bob' LIMIT 1";
* $row = $db->row($SQL);
* echo $row['name'];
*
* // multiple rows returned
* $SQL = "SELECT * FROM addressbook";
* $addresses = $db->get($SQL);
* foreach($addresses AS $address)
* echo $address['name'];
*
* // prematurely open
* $db->connect();
* // prematurely close
* $db->close(); // will reopen automatically if needed again
*
Click here for detailed information about this class on phpclasses.org