<pre>
<?php
include_once 'IDatabase.class.php';
include_once 'EException.class.php';
/*
* Example file for IDatabase class
*/
// Create database connection or die
$db = IDatabase::getSingleton();
echo "Connection successful.";
print "<p>SELECT ALL ROWS</p>";
// Get all data in an array from the sample table
$data = $db->select("SELECT * FROM sample");
// Print data
print_r($data);
print "<p>UPDATE ALL ROWS</p>";
// Update all row counter +1
$updatedRows = $db->update("UPDATE sample SET counter=counter+1;");
$data = $db->select("SELECT * FROM sample");
// Print data
print "Affected rows: ".$updatedRows."<br />";
print_r($data);
print "<p>INSERT RANDOM tester AND print last query string</p>";
$insertID = $db->insertA(array(
'table' => 'sample',
'name' => 'tester'.mt_rand(100,10000),
'counter' => '0',
));
print "Inserted ID: ".$insertID."<br />Insert Query: ".$db->getLastQuery();
print "<p>DELETE last inserted row (id: ".$insertID.")</p>";
$deletedRows = $db->delete("DELETE FROM sample WHERE id=".$insertID);
print "Query: ".$db->getLastQuery()."Affected rows: ".$deletedRows;
?>
</pre>
|