Using MySQL as a database engine in PHP is very powerful, but one thing that can be a pain is trying to debug code. Spotting the difference between a PHP error and a MySQL error can be hard with larger systems.
A good way of debugging MySQL code is by using the mysql_errno() and mysql_error() functions. These functions print off the last error that yuour MySQL server encountered so it can tell you exactly what is wrong with your SQL statements.
The following example code tries to get data from a non-existent table. The $result variable is set to false as the call failed so the error functions print off the SQL error.