Kill() is the same as die($db->Error()) or exit($db->Error());
if ($db->Error()) $db->Kill();
// You could also throw an exception on errors using:
// $db->ThrowExceptions = true;
$tables = $db->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);
}
// =========================================================================
// Example to insert a new row into a table and display it
// =========================================================================
// $arrayVariable["column name"] = formatted SQL value
$values["Color"] = Mysql::SQLValue("Violet");
$values["Age"] = Mysql::SQLValue(777, Mysql::SQLVALUE_NUMBER);
// Execute the insert
$result = $db->InsertRow("test", $values);
// If we have an error
if (! $result) {
// Show the error and kill the script
$db->Kill();
} else {
// No error, show the new record's ID
echo "The new record's ID is: " . $db->GetLastInsertID() . "\n
\n";
// Show the record using the values array to generate the WHERE clause
// We will use the SelectRows() method to query the database
$db->SelectRows("test", $values);
// Show the results in an HTML table
echo $db->GetHTML();
}
// =========================================================================
// Example to delete a row (or rows) in a table matching a filter
// =========================================================================
// Now let's delete that record using the same array for the WHERE clause
$db->DeleteRows("test", $values);
// =========================================================================
// Example to update an existing row into a table
// =========================================================================
// Create an array that holds the update information
// $arrayVariable["column name"] = formatted SQL value
$update["Color"] = Mysql::SQLValue("Red");
$update["Age"] = Mysql::SQLValue(123, Mysql::SQLVALUE_NUMBER);
// Create a filter array the detemrines which record(s) to process
// (you can specify more than one column if needed)
$where["TestID"] = Mysql::SQLValue(1, "integer");
// Execute the update
$result = $db->updateRows("test", $update, $where);
// If we have an error
if (! $result) {
// Show the error and kill the script
$db->Kill();
}
// --------------------------------------------------------------------------
// FYI: We can also shortcut and specify the "where" array in the call...
if (! $db->updateRows("test", $values, array("TestID" => 1))) $db->Kill();
// =========================================================================
// Here's a standard SQL query INSERT
// =========================================================================
// Build the INSERT SQL statement...
// (this could also be an UPDATE or DELETE SQL statement)
$sql = "INSERT INTO test (Color, Age) VALUES ('Red', '7')";
// Execute our query
if (! $db->Query($sql)) $db->Kill();
// Display the last autonumber ID field from the previous INSERT query
echo "The new ID for this record is " . $db->GetLastInsertID() . "
\r";
// =========================================================================
// The rest of this tutorial covers addition methods of inserting data into
// the database and is completely optional.
// =========================================================================
echo "