I recently ran into issues especially with using the Doctrine ORM with my PHP development. My issue was that sometimes database insert and update queries would fail and I would have very limited debugging tools at my disposal. You can try printing out the query but usually if you are binding values to the field names, they are not displayed in the printed output.
So after trying many varieties of debugging techniques I came across this post helping explaining how to enable query logging within MySQL itself.
I will explain how to enable this within a windows environment.
I am using Zend Server CE 5.5 in this instance, which installs MySQL Server 5.1.
- Go to the MySQL Server folder (c:\Program Files\Zend\MySQL51 in this instance)
- edit the my.ini file
- Look for the [mysqld] title name and anywhere in that area enter the following:
# The destination path for the log file for all MySQL transactions log="C:/Program Files/Zend/MySQL51/mysql.log
- Please change the path above to wherever you would like the log file to save to
- You will have to restart the MySQL service to enable the logging
- Click Start then Run and type in services.msc and press enter
- Find the MySQL_ZendServer51 or equivalent MySQL service and right click, restart
- After performing any MySQL interaction with the database, you should be able to open the log file described earlier and see every query that has been sent to the database engine.
With luck you will be able to view the exact query that has been failing and you can correct it.
I would highly recommend commenting out the logging feature once you have finished debugging as it will severely slow down your web server.