Consider the following two queries:
$result = db_query("SELECT nid, title FROM {node} WHERE type = 'article'"); // OK
$result = db_query('SELECT nid, title FROM {node} WHERE type = "article"'); // Fails
which should be identical in any database system that I'm familiar with.
The first one works, the second results in
Error message
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'article' in 'where clause': SELECT nid, title from {node} where type = "article"; Array ( ) in db_quotes_bug_page() (line 26 of /home/rfay/workspace/d7git/sites/all/modules/oneoff/db_quotes_bug/db_quotes_bug.module).
What I did: Used the second query
What I expected: A basic successful response to a simple static query
What I got instead: A PDOException.
I've tested a number of different queries, and it appears that this is just a problem with double quotes in the where clause.
The demo module I was using to test is attached.
Comments
Comment #1
rfayAttachment (demonstration module) got lost. Not sure why that happens so often.
Comment #2
damien tournoud commentedYou are not supposed to use *any* quotes in static queries. See discussion in #783814: db_query() should whitelist queries.
Comment #3
rfayI answered over there, but repeating here:
I certainly think that: