Converting db_query from Drupal 6 to Drupal 7: Invalid parameter number: number of bound variables does not match number of tokens 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' =&gt; $name['eng'], ':source_swe' =&gt; $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?
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' =&gt; $name['eng'], ':source_swe' =&gt; $name['swe']));