Display full query in the Exception of Zend_Db_Statement_Pdo

When working with Zend Framework 1.x and Zend_Db in particular, you might bump into an SQL problem like this

Syntax error or access violation: 
1064 You have an error in your SQL
syntax; check the manual that corresponds 
to your MySQL server version for 
the right syntax to use near ') 
ORDER BY `order` ASC' at line 1

OK, thanks a lot Zend, but what’s the query ?

the statement is kept inside $_stmt property of Zend_Db_Statement, and to display it, you need to acess the queryString property

$_stmt->queryString

Depending on the Zend version, the Zend_Db_Statement class might have a getter for it, so you can debug with

var_dump($zfDbStmt->getDriverStatement()->queryString);

You can also – of course – enable the MySQL general log and monitor the log file

[mysqld]
general_log_file = /path/to/logfile
general_log = 1