Esempio n. 1
0
/*  Micah's MySQL Database Class - Sample Usage 
 *  4.17.2005 - Micah Carrick, email@micahcarrick.com
 *
 *  This is a sample file on using my database class.  Hopefully it will provide
 *  you with enough information to use the class.  You should also look through
 *  the comments in the db.class.php file to get additional information about
 *  any specific function.
*/
require_once 'db.class.php';
$db = new db_class();
// Open up the database connection.  You can either setup your database login
// information in the db.class.php file or you can overide the defaults here.
// If you setup the default values, you just have to call $db->connect() without
// any parameters-- which is much easier.
if (!$db->connect('localhost', 'user', 'password', 'database_name', true)) {
    $db->print_last_error(false);
}
// Create the table (if it doesn't exist) by executing the external sql
// file with the create table SQL statement.
echo "Executing SQL commands in external file test_data.sql...<br>";
if (!$db->execute_file('test_data.sql')) {
    $db->print_last_error(false);
}
$db->print_last_query();
// This I find very handy.  You can build an array as you are working through,
// for example, POST variables and validating the data or formatting the data
// etc.  By defaul, the class will add slashes (addslashes()) to all string data
// being input using this function.  you can override that by doing:
// $db->auto_slashes = false;
// You cannot perform any MySQL functions when using insert_array() as the the
// function will be enclosed in quotes and not executed.  If you have some fancy