function _drush_replace_query_placeholders

8.0.x _drush_replace_query_placeholders($where, $args)
6.x _drush_replace_query_placeholders($where, $args)
7.x _drush_replace_query_placeholders($where, $args)
3.x _drush_replace_query_placeholders($where, $args)
4.x _drush_replace_query_placeholders($where, $args)
5.x _drush_replace_query_placeholders($where, $args)
master _drush_replace_query_placeholders($where, $args)

Replace named placeholders in a WHERE snippet.

Helper function to allow the usage of Drupal 7 WHERE snippets with named placeholders in code for Drupal 5 and 6.


$where: Stringwith a WHERE snippet using named placeholders.

$args: Array of placeholder values.

Return value

String. $where filled with literals from $args.

2 calls to _drush_replace_query_placeholders()
drush_db_delete in includes/
A db_delete() that works for any version of Drupal.
drush_db_select in includes/
A db_select() that works for any version of Drupal.


includes/, line 259
The drush API implementation and helpers.


function _drush_replace_query_placeholders($where, $args) {
  foreach ($args as $key => $data) {
    if (is_array($data)) {
      $new_keys = array();
      // $data can't have keys that are a prefix of other keys to
      // prevent a corrupted result in the below calls to str_replace().
      // To avoid this we will use a zero padded indexed array of the values of $data.
      $pad_length = strlen((string) count(array_values($data)));
      foreach (array_values($data) as $i => $value) {
        if (!is_numeric($value)) {
          $value = "'" . $value . "'";
        $new_keys[$key . '_' . str_pad($i, $pad_length, '0', STR_PAD_LEFT)] = $value;
      $where = preg_replace('#' . $key . '\b#', implode(', ', array_keys($new_keys)), $where);
      $args += $new_keys;
    else if (!is_numeric($data)) {
      $args[$key] = "'" . $data . "'";

  foreach ($args as $key => $data) {
    $where = str_replace($key, $data, $where);

  return $where;