Open()) $db->Kill(); // -------------------------------------------------------------------------- // Want to know if you are connected? Use IsConnected() echo "Are we connected? "; var_dump($db->IsConnected()); echo "\n
\n"; $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); } // -------------------------------------------------------------------------- // Now we can generate SQL statements from arrays! // Let's create an array for the examples // $arrayVariable["column name"] = formatted SQL value $values["Name"] = Mysql::SQLValue("Violet"); $values["Age"] = Mysql::SQLValue(777, Mysql::SQLVALUE_NUMBER); // Echo out some SQL statements echo "
" . "\n";
echo Mysql::BuildSQLDelete("test", $values) . "\n
\n"; echo Mysql::BuildSQLInsert("test", $values) . "\n
\n"; echo Mysql::BuildSQLSelect("test", $values) . "\n
\n"; echo Mysql::BuildSQLUpdate("test", $values, $values) . "\n
\n"; echo Mysql::BuildSQLWhereClause($values) . "\n
\n"; echo "
" . "\n"; // Or create more advanced SQL SELECT statements $columns = array("Name", "Age"); $sort = "Name"; $limit = 10; echo Mysql::BuildSQLSelect("test", $values, $columns, $sort, true, $limit); echo "\n
\n"; $columns = array("Color Name" => "Name", "Total Age" => "Age"); $sort = array("Age", "Name"); $limit = "10, 20"; echo Mysql::BuildSQLSelect("test", $values, $columns, $sort, false, $limit); echo "\n
\n"; // The following methods take the same parameters and automatically execute! // $db->DeleteRows("test", $values); // $db->InsertRow("test", $values); // $db->SelectRows("test", $values, $columns, $sort, true, $limit); // $db->UpdateRows("test", $values1, $values2); // You can also select an entire table // $db->SelectTable("test"); // Or truncate and clear out an entire table // $db->TruncateTable("test"); // -------------------------------------------------------------------------- // Now you can throw exceptions and use try/catch blocks $db->ThrowExceptions = true; try { // This next line will always cause an error $db->Query("BAD SQL QUERY TO CREATE AN ERROR"); } catch (Exception $e) { // If an error occurs, do this (great for transaction processing!) echo "We caught the error: " . $e->getMessage(); } // Or let's show a stack trace if we do not use a try/catch // This shows the stack and tells us exactly where it failed $db->Query("BAD SQL QUERY TO CREATE AN ERROR");