<?php
// before running this example make sure you import the "example.sql" file
// from the "examples" folder, into your mySQL!
// include the class
require "../class.database.php";
// create a new database object
$db = new database();
// show debugging info
// remember: if you not set this to TRUE,
// the show_debug_info() method will show nothing
$db->debug = true;
// make the connection
$db->connect(
"host",
"user",
"password",
"database"
);
// set the maximum time limit (in seconds) after which a query is considered to be running for too long
$db->maxQueryTime = 10;
// the address where to send notifications if a query has run for more than the above specified time limit
$db->maxQueryTimeExceeded_notificationAddress = "hide@address.com";
// run a simple query
$result = $db->query("
SELECT *
FROM
test
LIMIT 1,2
"
,"" , __FILE__, __LINE__);
print_r("<br /><br />");
// this will print the number of the records in the table ignoring the LIMIT
print_r($db->foundRows);
// print the current value of $foundRows in the watch
$db->watch($db->foundRows, "foundRows");
// run a simple query
// note that "?" will be automatically replaced with the corresponding escaped value from the
// array
$result = $db->query("
SELECT *
FROM
test
WHERE
age > ?
",
array(25), __FILE__, __LINE__);
// print the resulting names
while ($row = $db->fetch_assoc($result)) {
print_r("<br /><br />");
print_r($row["name"]);
}
print_r("<br /><br />");
// make a specific lookup
// this will print "1" as the id of the record is 1
print_r($db->dlookup("id", "test", "name = 'Darth Vader'", __FILE__, __LINE__));
print_r("<br /><br />");
// get the maximum age in the table
// this will print "50"
// (remember to check the manual for other methods like dsum and dcount)
print_r($db->dmax("age", "test", "", __FILE__, __LINE__));
// do a wrong query
$result = $db->query("
SELECT * FROM nonexistingtable
"
, "", __FILE__, __LINE__);
// show debug info
$db->show_debug_info();
?>