GetTables();
if (!in_array('test', $tables)) {
$qry = 'CREATE TABLE `test` (
`TestID` int(10) NOT NULL auto_increment,
`Color` varchar(15) default NULL,
`Age` int(10) default NULL,
PRIMARY KEY (`TestID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
$db = new Mysql();
$db->query($qry);
}
/*
-- --------------------------------------------
-- SQL to generate test table
-- --------------------------------------------
CREATE TABLE `test` (
`TestID` int(10) NOT NULL auto_increment,
`Color` varchar(15) default NULL,
`Age` int(10) default NULL,
PRIMARY KEY (`TestID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf-8;
-- --------------------------------------------
*/
// --- Open the database --------------------------------------------
// (Also note that you can fill in the variables in the top of the class
// if you want to automatically connect when the object is created. If
// you fill in the values when you create the obect, this is not needed.)
if (! $db->Open()) {
$db->Kill();
}
echo "You are connected to the database
\n";
// --- Insert a new record ------------------------------------------
$sql = "INSERT INTO Test (Color, Age) Values ('Red', 7)";
if (! $db->Query($sql)) {
$db->Kill();
}
echo "Last ID inserted was: " . $db->GetLastInsertID();
// --- Or insert a new record with transaction processing -----------
$sql = "INSERT INTO Test (Color, Age) Values ('Blue', 3)";
$db->TransactionBegin();
if ($db->Query($sql)) {
$db->TransactionEnd();
echo "Last ID inserted was: " . $db->GetLastInsertID() . "
\n";
} else {
$db->TransactionRollback();
echo "
Query Failed
\n"; } // --- Query and show the data -------------------------------------- // (Note: $db->Query also returns the result set) if ($db->Query("SELECT * FROM Test")) { echo $db->GetHTML(); } else { echo "Query Failed
"; } // --- Getting the record count is easy ----------------------------- echo "\nRecord Count: " . $db->RowCount() . "
\n"; // --- Loop through the records ------------------------------------- while ($row = $db->Row()) { echo $row->Color . " - " . $row->Age . "There were no errors
\n"; } // --- Format some values ready for SQL ----------------------------- // You do not have to create the object to use these. Simply include // the class in your PHP file. These are called "Static" methods. echo "