G Saunders Home Page

Debugging PHP, JavaScript, and MySQL in PHP

Tailing the Error Log to Debug PHP

PLEASE NOTE!!!! Since this video was made, info465.us has been secured with ssl. The error log is now /var/log/httpd/ssl_error_log, it is no longer at /var/log/httpd/error_log.

Video: Tailing the Error Log and Debugging PHP

Debugging JavaScript with Developer's Tools Web Console

Debugging is sometimes complicated when an ISP like VCUNet and some others 'aggressively caches' static content. If you just use Ctrl-r or click the page's Refresh button, the JavaScript and CSS may not be refreshed.

It's important to recognize when this happens and use the browser's Ctrl-u or View Source to open a new tab with the page's source visible. Then, click on the JavaScript link to show the JavaScript's source. Then, use Ctrl-r or the Refresh button to 'explicitly refresh' the JavaScript.

When you see the Refreshed source code is the current version with your changes, go back to the web page and refresh it.

This aggressive cacheing also complicates debugging CSS and it can be explicitly refreshed the same way.

If there are errors in the JavaScript to debug, use FireFox or Chrome to debug using their Developer's Tools menu to open the Web Console where JavaScript errors are displayed. This video demonstrates debugging JavaScript with the Web Console and also by placing alert() boxes in the code to display current values and help to locate the error.

Video: Debugging JavaScript with FireFox or Chrome's Web Console

Pasting MySQL Statements into MySQL to Debug

If an SQL statement embedded in PHP code is not getting the expected results it's helpful to echo the statement to the browser so you can copy the _exact_ statement and paste it into the MySQL/MariaDB command line to see the error messages MySQL produces. When debugging the PHP script, the only thing you know is that the statement didn't work. Pasting the statement into the database's command line and running it there usually points out the error so it can be fixed.

Video: Debugging SQL in PHP code


G Saunders,
Dept of Information Systems
VCU School of Business

G Saunders Wings

Content © 1999 - Today
By G Saunders
Images are Available on the Web