I believe that error means that the query string isn't getting fed to the prepare method correctly... where it says "<query string>" in your code snippet, what does it literally say in your script? Is it a literal string? A variable? I've encountered that error when I accidentally squashed the variable I was using to hold my query string....
I dunno; hope this helps.