I am migrating custom modules from Drupal 6 to 7. Since the database API changed it's quite a lot to do. During this I stumbled upon a problem regarding quotes. I am used to enclose strings in PHP with single quotes, so in Drupal 6 I wrote

$q = 'SELECT * FROM {node} WHERE type = "page"';

However, without any pattern (as far as I could detect) some of these queries fail in Drupal 7. When changing the above line to

$q = "SELECT * FROM {node} WHERE type = 'page'";

it suddenly works. But I couldn't find any information if this quoting style is required by the new DAL. Anybody got further information on that or can confirm my observation?

  • Not sure. But may be {node} did not work because of single quote. – Hacker Jan 10 '12 at 11:49
  • No, that's actually working fine. See answer by ovidyou for the cause of trouble. – Paul Jan 10 '12 at 12:55

Some SQL database engines are not supporting double quotes inside the query, that's why it didn't work out for you. Read more here: db_query#comment-11959.

  • Thanks, this made it more clear. Still wondering though, because I am running the D7 site on the same server with the same database as before in D6. In fact, not the quotes of the query itself are causing the trouble but the quotes on the values. Apparently, these have to be in single quotes. – Paul Jan 10 '12 at 12:53
  • 1
    Well, the D7 DAL is built on top of PHP PDO. On PDO Introduction page can be found the following "PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features.", so I think DAL might be responsible of the not working queries that contain double quotes inside, since you are using the same DB type and double quotes have worked with D6. – ovi Jan 10 '12 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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