1

I have a custom localisation function in a Drupal 6 module that I would like to convert to Drupal 7 but I have hit a wall with the db_query function. I have the following code (in d6 and d7):

// Drupal 6
db_query("REPLACE INTO {locales_target} (lid, translation, language) VALUES ((SELECT lid FROM {locales_source} WHERE source = '%s' LIMIT 1), '%s', 'sv')", $name['eng'], $name['swe']);

// Drupal 7 (not working)
db_query("REPLACE INTO {locales_target} (lid, translation, language) VALUES ((SELECT lid FROM {locales_source} WHERE source = :source_eng LIMIT 1), ':source_swe', 'sv')", array(':source_eng' => $name['eng'], ':source_swe' => $name['swe']));

I get the following error message when I try to use the d7 version:

PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

D7 API for db_query

Could somebody help me out figuring why the db_query isn't working?

1
  • 1
    looks like it should work, what are the values of the $name[''] variables? Commented Jul 22, 2014 at 13:01

1 Answer 1

0

You've quoted one of the parameters when you shouldn't have.

PDO interprets this:

':source_swe'

as a string, and it (correctly) doesn't try to change it.

What you're looking for is simply

:source_swe

So that parameter replacement can occur. As in,

db_query("REPLACE INTO {locales_target} (lid, translation, language) VALUES ((SELECT lid FROM {locales_source} WHERE source = :source_eng LIMIT 1), :source_swe, 'sv')", array(':source_eng' => $name['eng'], ':source_swe' => $name['swe']));
0

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.