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 the PHP DB class.
May the link be broken, you can download it on the phpkode.com mirror
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).
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
Debug: SELECT * FROM Users
Users | uid | login | pass | remember | onlyIcons | newPassId | newPassDate |
---|---|---|---|---|---|---|---|
1 | monuser1 | 65b53cf06633e3e7b6a98f3905c75939 | monuser1@fr.st | 1 | 0 | 0000-00-00 00:00:00 | |
2 | foobar | 3858f62230ac3c915f300c664312c63f | foo@bar.org | 1 |
Debug: UPDATE Users SET remember=1
Number of affected rows: 2
0.073 s ; 4
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
Default Debug: SELECT * FROM Users
Users | uid | login | pass | remember | onlyIcons | newPassId | newPassDate |
---|---|---|---|---|---|---|---|
1 | monuser1 | 65b53cf06633e3e7b6a98f3905c75939 | monuser1@fr.st | 1 | 0 | 0000-00-00 00:00:00 | |
2 | foobar | 3858f62230ac3c915f300c664312c63f | foo@bar.org | 1 |
Debug: SELECT * FROM Users
Users | uid | login | pass | remember | onlyIcons | newPassId | newPassDate |
---|---|---|---|---|---|---|---|
1 | monuser1 | 65b53cf06633e3e7b6a98f3905c75939 | monuser1@fr.st | 1 | 0 | 0000-00-00 00:00:00 | |
2 | foobar | 3858f62230ac3c915f300c664312c63f | foo@bar.org | 1 |
Debug: UPDATE Users SET remember=1
Number of affected rows: 2
Default Debug: SELECT * FROM Users WHERE uid=3 LIMIT 1
Users | uid | login | pass | remember | onlyIcons | newPassId | newPassDate |
---|
0.011 s ; 4
Error: SELECT * FROM NotExistingTable
Table 'slaout.NotExistingTable' doesn't exist