db_query($query, $args = array(), $options = array())
drupal/includes/database/database.inc, line 1541
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 DatabaseConnection::defaultOptions()
$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.
A prepared statement object, already executed.
| Name | Description |
|---|---|
| Database abstraction layer | Allow the use of different database servers using the same code base. |
| Schema API | A Drupal schema definition is an array structure representing one or more tables and their related keys and indexes. A schema is defined by hook_schema(), which usually lives in a modulename.install file. |
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);
}