db_query

Definition

db_query($query, $args = array(), $options = array())
includes/database/database.inc, line 1146

Description

Execute an arbitrary query string against the active database.

Do not use this function for INSERT, UPDATE, or DELETE queries. Those should be handled via the appropriate query builder factory. Use this function for SELECT queries that do not require a query builder.

See also

DatabaseConnection::defaultOptions()

Parameters

$query The prepared statement query to run. Although it will accept both named and unnamed placeholders, named placeholders are strongly preferred as they are more self-documenting.

$args An array of values to substitute into the query. If the query uses named placeholders, this is an associative array in any order. If the query uses unnamed placeholders (?), this is an indexed array and the order must match the order of placeholders in the query string.

$options An array of options to control how the query operates.

Return value

A prepared statement object, already executed.

Related topics

Namesort iconDescription
Database abstraction layerAllow the use of different database servers using the same code base.

Code

<?php
function db_query($query, $args = array(), $options = array()) {
  if (!is_array($args)) {
    $args = func_get_args();
    array_shift($args);
  }
  list($query, $args, $options) = _db_query_process_args($query, $args, $options);

  return Database::getActiveConnection($options['target'])->query($query, $args, $options);
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.