Error()) $db->Kill();
// Or use: if ($db->Error()) die($db->Error());
// Or: if ($db->Error()) echo $db->Error();
$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);
}
// Execute our query
if (! $db->Query("SELECT * FROM Test")) $db->Kill();
// Let's show how many records were returned
echo $db->RowCount() . " records returned.
\n
\n";
// Loop through the records using the Mysql object (prefered)
$db->MoveFirst();
while (! $db->EndOfSeek()) {
$row = $db->Row();
echo "Row " . $db->SeekPosition() . ": ";
echo $row->Color . " and " . $row->Age . "
\n";
}
// =========================================================================
// The rest of this tutorial covers addition methods of getting to the data
// and is completely optional.
// =========================================================================
echo "
\n"; // ---------------------------------------------------------
// Loop through the records using a counter and display the values
for ($index = 0; $index < $db->RowCount(); $index++) {
$row = $db->Row($index);
echo "Index " . $index . ": ";
echo $row->Color . " and " . $row->Age . "
\n";
}
echo "
\n"; // ---------------------------------------------------------
// Now let's just show all the data as an HTML table
// This method is great for testing or displaying simple results
echo $db->GetHTML(false);
echo "
\n"; // ---------------------------------------------------------
// Now let's grab the first row of data as an associative array
// The paramters are completely optional. Every time you grab a
// row, the cursor is automatically moved to the next row. Here,
// we will specify the the first row (0) to reset our position.
// We will also specify what type of array we want returned.
$array = $db->RowArray(0, MYSQL_ASSOC);
// Display the array
echo "\n";
print_r($array);
echo "
\n";
echo "
\n"; // ---------------------------------------------------------
// And now show the individual columns in the array
echo $array['Color'] . " and " . $array['Age'] . "
\n";
// Grab the next row as an array. Notice how we didn't specify
// a row (0) like above? It's completely optional.
$array = $db->RowArray();
echo $array['Color'] . " and " . $array['Age'] . "
\n";
// There are so many different ways to use the Ultimate Mysql class!