I am using a feeds hook to email some information to workbench section users. I've been changing some of my code and suddently I'm getting a database error:

SQLSTATE[42000]: 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 '))' at line 2

This error doesn't show enough of the query to let me know which one it is, what line number or function it originates in, etc. I've tried putting a debug_backtrace() in the core definition of the drupal_set_message() function but I did not find my functions in it, just batch functions. I also tried putting backtraces in the DatabaseStatementBase classes' execute() method, but that caused the site to output a bunch of junk information on the screen.

How can I backtrace this error or otherwise track it down? The only thing that occurs to me put error messages around each query I'm running to see where the actual error falls. Is this the best way?

1 Answer 1


turn on error reporting for php. turn on mysql query log and inspect new queries -- add a simple parameter you can lookup like SELECT ..., 'IS-THIS-BROKEN-1' as debug_key to easily find your quer(ies) in the mysql log file. ... Views offer such a debug parameter for views sql queries too ... my point is there are better ways to tackle this that strictly form your PHP code and drupal_set_message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.