Home / PHP Advanced Database Class

Here is a PHP class to facilitate PHP/MySQL development.
It propose convenient methods and an easy way to access a database by reducing the amount of code you should write. It also provides debugging facilities: you can display the request and the resulting table by just adding a parameter to the methods of this class. Queries are automatically debugged when there is an error.

Download

Download the PHP DB class.
May the link be broken, you can download it on the phpkode.com mirror

Quick Overview

Here are typical usages: a quick overview of all functions.

You can also view the doxygen documentation (it list and provide documentation for all available methods).

Example of Debugging

Here are examples of how powerful the class is when it comes to debugging queries.
You can debug each queries one by one by setting the second parameter to true:

$db->defaultDebug is false

$db->query("SELECT * FROM Users");

$db->query("SELECT * FROM Users", true);

Debug: SELECT * FROM Users

Users
uidloginpassmailrememberonlyIconsnewPassIdnewPassDate
1monuser165b53cf06633e3e7b6a98f3905c75939monuser1@fr.st100000-00-00 00:00:00
2foobar3858f62230ac3c915f300c664312c63ffoo@bar.org1

$db->execute("UPDATE Users SET remember=1", true);

Debug: UPDATE Users SET remember=1

Number of affected rows: 2

$db->queryUniqueObject("SELECT * FROM Users WHERE uid=3");

getExecTime() ; getQueriesCount() [SHOULD be at end of the PHP script (but we generate an error below)]

0.073 s ; 4

Test of erroneous query

Error: SELECT * FROM NotExistingTable

Table 'slaout.NotExistingTable' doesn't exist

But you also can debug every queries at once by setting the $defaultDebug variable in the class DB to true:

$db->defaultDebug is true

$db->query("SELECT * FROM Users");

Default Debug: SELECT * FROM Users

Users
uidloginpassmailrememberonlyIconsnewPassIdnewPassDate
1monuser165b53cf06633e3e7b6a98f3905c75939monuser1@fr.st100000-00-00 00:00:00
2foobar3858f62230ac3c915f300c664312c63ffoo@bar.org1

$db->query("SELECT * FROM Users", true);

Debug: SELECT * FROM Users

Users
uidloginpassmailrememberonlyIconsnewPassIdnewPassDate
1monuser165b53cf06633e3e7b6a98f3905c75939monuser1@fr.st100000-00-00 00:00:00
2foobar3858f62230ac3c915f300c664312c63ffoo@bar.org1

$db->execute("UPDATE Users SET remember=1", true);

Debug: UPDATE Users SET remember=1

Number of affected rows: 2

$db->queryUniqueObject("SELECT * FROM Users WHERE uid=3");

Default Debug: SELECT * FROM Users WHERE uid=3 LIMIT 1

Users
uidloginpassmailrememberonlyIconsnewPassIdnewPassDate

getExecTime() ; getQueriesCount() [SHOULD be at end of the PHP script (but we generate an error below)]

0.011 s ; 4

Test of erroneous query

Error: SELECT * FROM NotExistingTable

Table 'slaout.NotExistingTable' doesn't exist