Database abstraction layer

  1. drupal
    1. drupal6 database.inc
    2. drupal7

Allow the use of different database servers using the same code base.

Drupal provides a database abstraction layer to provide developers with the ability to support multiple database servers easily. The intent of this layer is to preserve the syntax and power of SQL as much as possible, but also allow developers a way to leverage more complex functionality in a unified way. It also provides a structured interface for dynamically constructing queries when appropriate, and enforcing security checks and similar good practices.

The system is built atop PHP's PDO (PHP Data Objects) database API and inherits much of its syntax and semantics.

Most Drupal database SELECT queries are performed by a call to db_query() or db_query_range(). Module authors should also consider using pager_query() for queries that return results that need to be presented on multiple pages, and tablesort_sql() for generating appropriate queries for sortable tables.

For example, one might wish to return a list of the most recent 10 nodes authored by a given user. Instead of directly issuing the SQL query

<?php

  SELECT n.nid, n.title, n.created FROM node n WHERE n.uid = $uid LIMIT 0, 10;

?>

one would instead call the Drupal functions:

<?php

  $result = db_query_range('SELECT n.nid, n.title, n.created
    FROM {node} n WHERE n.uid = :uid', array(':uid' => $uid), 0, 10);
  foreach($result as $record) {
    // Perform operations on $node->title, etc. here.
  }

?>

Curly braces are used around "node" to provide table prefixing via DatabaseConnection::prefixTables(). The explicit use of a user ID is pulled out into an argument passed to db_query() so that SQL injection attacks from user input can be caught and nullified. The LIMIT syntax varies between database servers, so that is abstracted into db_query_range() arguments. Finally, note the PDO-based ability to foreach() over the result set.

All queries are passed as a prepared statement string. A prepared statement is a "template" of a query that omits literal or variable values in favor of placeholders. The values to place into those placeholders are passed separately, and the database driver handles inserting the values into the query in a secure fashion. That means you should never quote or string-escape a value to be inserted into the query.

There are two formats for placeholders: named and unnamed. Named placeholders are strongly preferred in all cases as they are more flexible and self-documenting. Named placeholders should start with a colon ":" and can be followed by one or more letters, numbers or underscores.

Named placeholders begin with a colon followed by a unique string. Example:

<?php

SELECT nid, title FROM {node} WHERE uid=:uid

?>

":uid" is a placeholder that will be replaced with a literal value when the query is executed. A given placeholder label cannot be repeated in a given query, even if the value should be the same. When using named placeholders, the array of arguments to the query must be an associative array where keys are a placeholder label (e.g., :uid) and the value is the corresponding value to use. The array may be in any order.

Unnamed placeholders are simply a question mark. Example:

<?php

SELECT nid, title FROM {node} WHERE uid=?

?>

In this case, the array of arguments must be an indexed array of values to use in the exact same order as the placeholders in the query.

Note that placeholders should be a "complete" value. For example, when running a LIKE query the SQL wildcard character, %, should be part of the value, not the query itself. Thus, the following is incorrect:

<?php

SELECT nid, title FROM {node} WHERE title LIKE :title%

?>

It should instead read:

<?php

SELECT nid, title FROM {node} WHERE title LIKE :title

?>

and the value for :title should include a % as appropriate. Again, note the lack of quotation marks around :title. Because the value is not inserted into the query as one big string but as an explicitly separate value, the database server knows where the query ends and a value begins. That is considerably more secure against SQL injection than trying to remember which values need quotation marks and string escaping and which don't.

INSERT, UPDATE, and DELETE queries need special care in order to behave consistently across all different databases. Therefore, they use a special object-oriented API for defining a query structurally. For example, rather than

<?php

INSERT INTO node (nid, title, body) VALUES (1, 'my title', 'my body')

?>

one would instead write:

<?php

$fields = array('nid' => 1, 'title' => 'my title', 'body' => 'my body');
db_insert('my_table')->fields($fields)->execute();

?>

This method allows databases that need special data type handling to do so, while also allowing optimizations such as multi-insert queries. UPDATE and DELETE queries have a similar pattern.

Drupal also supports transactions, including a transparent fallback for databases that do not support transactions. To start a new transaction, simply call $txn = db_transaction(): in your own code. The transaction will remain open for as long as the variable $txn remains in scope. When $txn is destroyed, the transaction will be committed. If your transaction is nested inside of another then Drupal will track each transaction and only commit the outer-most transaction when the last transaction object goes out out of scope, that is, all relevant queries completed successfully.

Example:

<?php

function my_transaction_function() {
  // The transaction opens here.
  $txn = db_transaction();

  try {
    $id = db_insert('example')
      ->fields(array(
        'field1' => 'mystring',
        'field2' => 5,
      ))
      ->execute();

    my_other_function($id);

    return $id;
  }
  catch (Exception $e) {
    // Something went wrong somewhere, so flag the entire transaction to
    // roll back instead of getting committed.  It doesn't actually roll back
    // yet, just gets flagged to do so.
    $txn->rollback();
  }

  // $txn goes out of scope here.  If there was a problem, it rolls back
  // automatically.  If not, it commits automatically.
}

function my_other_function($id) {
  // The transaction is still open here.

  if ($id % 2 == 0) {
    db_update('example')
      ->condition('id', $id)
      ->fields(array('field2' => 10))
      ->execute();
  }
}

?>

Klassen

NameBeschreibung
DatabasePrimary front-controller for the database system.
DatabaseConditionGeneric class for a series of conditions in a query.
DatabaseConnectionBase Database API class.
DatabaseConnection_mysql
DatabaseConnection_pgsql
DatabaseConnection_sqliteSpecific SQLite implementation of DatabaseConnection.
DatabaseStatementBaseDefault implementation of DatabaseStatementInterface.
DatabaseStatementPrefetchAn implementation of DatabaseStatementInterface that prefetches all data.
DatabaseStatement_sqliteSpecific SQLite implementation of DatabaseConnection.
DatabaseTransactionA wrapper class for creating and managing database transactions.
DeleteQueryGeneral class for an abstracted DELETE operation.
DeleteQuery_sqliteSQLite specific implementation of DeleteQuery.
ExplicitTransactionsNotSupportedExceptionException to deny attempts to explicitly manage transactions.
InsertQueryGeneral class for an abstracted INSERT operation.
InsertQuery_mysql
InsertQuery_pgsql
InsertQuery_sqliteSQLite specific implementation of InsertQuery.
InvalidMergeQueryExceptionException thrown for merge queries that do not make semantic sense.
MergeQueryGeneral class for an abstracted MERGE operation.
MergeQuery_mysql
NoActiveTransactionExceptionException to throw when popTransaction() is called when no transaction is active.
QueryBase class for the query builders.
SelectQueryQuery builder for SELECT statements.
SelectQueryExtenderThe base extender class for Select queries.
TransactionsNotSupportedExceptionException to mark databases that do not support transations.
TruncateQueryGeneral class for an abstracted TRUNCATE operation.
TruncateQuery_sqliteSQLite specific implementation of TruncateQuery.
UpdateQueryGeneral class for an abstracted UPDATE operation.
UpdateQuery_pgsql
UpdateQuery_sqliteSQLite specific implementation of UpdateQuery.

Konstanten

NameBeschreibung
Flag to indicate a query call should return the "last insert id".

Properties

NameBeschreibung
/** * A list of key/target credentials to simply ignore. * * @var array */ static protected $ignoreTargets = array()A list of key/target credentials to simply ignore.
/** * A processed copy of the database connection information from settings.php * * @var array */ static protected $databaseInfo = NULLA processed copy of the database connection information from settings.php
/** * An array of active query log objects. * * Every connection has one and only one logger object for all targets * and logging keys. * * array( * '$db_key' => DatabaseLog object. * ); * * @var array */ static protected $logs = array()An array of active query log objects.
/** * An nested array of all active connections. It is keyed by database name and target. * * @var array */ static protected $connections = array()An nested array of all active connections. It is keyed by database name and target.
/** * The key of the currently active database connection. * * @var string */ static protected $activeKey = 'default'The key of the currently active database connection.
protected $arguments = array()
protected $changed = TRUE
protected $conditions = array()
/** * An index used to generate unique temporary table names. * * @var integer */ protected $temporaryNameIndex = 0An index used to generate unique temporary table names.
/** * Cache of prepared statements. * * This cache only lasts as long as the current page request, so it's not * as useful as it could be, but every little bit helps. * * @var Array */ protected $preparedStatements = array()Cache of prepared statements.
/** * Reference to the last statement that was executed. * * We only need this for the legacy db_affected_rows() call, which will be removed. * * @var DatabaseStatementInterface * @todo Remove this variable. */ public $lastStatementReference to the last statement that was executed.
/** * The current database logging object for this connection. * * @var DatabaseLog */ protected $logger = NULLThe current database logging object for this connection.
/** * The database target this connection is for. * * We need this information for later auditing and logging. * * @var string */ protected $target = NULLThe database target this connection is for.
/** * The name of the Delete class for this connection. * * @var string */ protected $deleteClass = NULLThe name of the Delete class for this connection.
/** * The name of the Insert class for this connection. * * @var string */ protected $insertClass = NULLThe name of the Insert class for this connection.
/** * The name of the Merge class for this connection. * * @var string */ protected $mergeClass = NULLThe name of the Merge class for this connection.
/** * The name of the Select class for this connection. * * Normally this and the following class names would be static variables, * but statics in methods are still global and shared by all instances. * * @var string */ protected $selectClass = NUThe name of the Select class for this connection.
/** * The name of the Statement class for this connection. * * @var string */ protected $statementClass = 'DatabaseStatementBase'The name of the Statement class for this connection.
/** * The name of the Transaction class for this connection. * * @var string */ protected $transactionClass = NULLThe name of the Transaction class for this connection.
/** * The name of the Truncate class for this connection. * * @var string */ protected $truncateClass = NULLThe name of the Truncate class for this connection.
/** * The name of the Update class for this connection. * * @var string */ protected $updateClass = NULLThe name of the Update class for this connection.
/** * The schema object for this connection. * * @var object */ protected $schema = NULLThe schema object for this connection.
/** * Track the number of "layers" of transactions currently active. * * On many databases transactions cannot nest. Instead, we track * nested calls to transactions and collapse them into a single * transaction. * * @var int */ protected $transaTrack the number of "layers" of transactions currently active.
/** * Whether or not the active transaction (if any) will be rolled back. * * @var boolean */ protected $willRollBackWhether or not the active transaction (if any) will be rolled back.
/** * Whether this database connection supports transactional DDL. * * Set to FALSE by default because few databases support this feature. * * @var bool */ protected $transactionalDDLSupport = FALSEWhether this database connection supports transactional DDL.
/** * Whether this database connection supports transactions. * * @var bool */ protected $transactionSupport = TRUEWhether this database connection supports transactions.
/** * Reference to the database connection object for this statement. * * The name $dbh is inherited from PDOStatement. * * @var DatabaseConnection */ public $dbhReference to the database connection object for this statement.
/** * Driver-specific options. Can be used by child classes. * * @var Array */ protected $driverOptionsDriver-specific options. Can be used by child classes.
/** * Holds supplementary current fetch options (which will be used by the next fetch). * * @var Array */ protected $fetchOptions = array( 'class' => 'stdClass', 'constructor_args' => array(), 'object' => NULL, 'column' => 0, )Holds supplementary current fetch options (which will be used by the next fetch).
/** * Holds supplementary default fetch options. * * @var Array */ protected $defaultFetchOptions = array( 'class' => 'stdClass', 'constructor_args' => array(), 'object' => NULL, 'column' => 0, )Holds supplementary default fetch options.
/** * Holds the current fetch style (which will be used by the next fetch). * @see PDOStatement::fetch() * * @var int */ protected $fetchStyle = PDO::FETCH_OBJHolds the current fetch style (which will be used by the next fetch).
/** * Holds the default fetch style. * * @var int */ protected $defaultFetchStyle = PDO::FETCH_OBJHolds the default fetch style.
/** * Main data store. * * @var Array */ protected $data = array()Main data store.
/** * Reference to the database connection object for this statement. * * The name $dbh is inherited from PDOStatement. * * @var DatabaseConnection */ public $dbhReference to the database connection object for this statement.
/** * The current row, retrieved in PDO::FETCH_ASSOC format. * * @var Array */ protected $currentRow = NULLThe current row, retrieved in PDO::FETCH_ASSOC format.
/** * The key of the current row. * * @var int */ protected $currentKey = NULLThe key of the current row.
/** * The list of column names in this result set. * * @var Array */ protected $columnNames = NULLThe list of column names in this result set.
/** * The number of rows affected by the last query. * * @var int */ protected $rowCount = NULLThe number of rows affected by the last query.
/** * The number of rows in this result set. * * @var int */ protected $resultRowCount = 0The number of rows in this result set.
/** * The query string. * * @var string */ protected $queryStringThe query string.
/** * The connection object for this transaction. * * @var DatabaseConnection */ protected $connectionThe connection object for this transaction.
/** * The condition object for this query. Condition handling is handled via * composition. * * @var DatabaseCondition */ protected $conditionThe condition object for this query. Condition handling is handled via composition.
/** * The table from which to delete. * * @var string */ protected $tableThe table from which to delete.
/** * A nested array of values to insert. * * $insertValues itself is an array of arrays. Each sub-array is an array of * field names to values to insert. Whether multiple insert sets * will be run in a single query or multiple queries is left to indA nested array of values to insert.
/** * An array of fields on which to insert. * * @var array */ protected $insertFields = array()An array of fields on which to insert.
/** * An array of fields which should be set to their database-defined defaults. * * @var array */ protected $defaultFields = array()An array of fields which should be set to their database-defined defaults.
/** * The table on which to insert. * * @var string */ protected $tableThe table on which to insert.
/** * Whether or not this query is "delay-safe". Different database drivers * may or may not implement this feature in their own ways. * * @var boolean */ protected $delayWhether or not this query is "delay-safe". Different database drivers may or may not implement this feature in their own ways.
/** * An array of fields on which to insert. * * @var array */ protected $insertFields = array()An array of fields on which to insert.
/** * An array of fields to not update in case of a duplicate record. * * @var array */ protected $excludeFields = array()An array of fields to not update in case of a duplicate record.
/** * An array of fields to update instead of the values specified in * $insertFields; * * @var array */ protected $updateFields = array()An array of fields to update instead of the values specified in $insertFields;
/** * An array of fields to update to an expression in case of a duplicate record. * * This variable is a nested array in the following format: * <some field> => array( * 'condition' => <condition to execute, as a string> * 'arguments' => <array oAn array of fields to update to an expression in case of a duplicate record.
/** * An array of key fields for this query. * * @var array */ protected $keyFields = array()An array of key fields for this query.
/** * The table on which to insert. * * @var string */ protected $tableThe table on which to insert.
/** * The connection object on which to run this query. * * @var DatabaseConnection */ protected $connectionThe connection object on which to run this query.
/** * The query options to pass on to the connection object. * * @var array */ protected $queryOptionsThe query options to pass on to the connection object.
/** * The conditional object for the HAVING clause. * * @var DatabaseCondition */ protected $havingThe conditional object for the HAVING clause.
/** * The conditional object for the WHERE clause. * * @var DatabaseCondition */ protected $whereThe conditional object for the WHERE clause.
/** * The expressions to SELECT as virtual fields. * * @var array */ protected $expressions = array()The expressions to SELECT as virtual fields.
/** * The fields by which to group. * * @var array */ protected $group = array()The fields by which to group.
/** * The fields by which to order this query. * * This is an associative array. The keys are the fields to order, and the value * is the direction to order, either ASC or DESC. * * @var array */ protected $order = array()The fields by which to order this query.
/** * The fields to SELECT. * * @var array */ protected $fields = array()The fields to SELECT.
/** * The range limiters for this query. * * @var array */ protected $rangeThe range limiters for this query.
/** * The tables against which to JOIN. * * This property is a nested array. Each entry is an array representing * a single table against which to join. The structure of each entry is: * * array( * 'type' => $join_type (one of INNER, LEFT OUTER, The tables against which to JOIN.
/** * Whether or not this query should be DISTINCT * * @var boolean */ protected $distinct = FALSEWhether or not this query should be DISTINCT
/** * The connection object on which to run this query. * * @var DatabaseConnection */ protected $connectionThe connection object on which to run this query.
/** * The SelectQuery object we are extending/decorating. * * @var SelectQueryInterface */ protected $queryThe SelectQuery object we are extending/decorating.
/** * The table from which to delete. * * @var string */ protected $tableThe table from which to delete.
/** * An array of fields that will be updated. * * @var array */ protected $fields = array()An array of fields that will be updated.
/** * An array of fields to update to an expression in case of a duplicate record. * * This variable is a nested array in the following format: * <some field> => array( * 'condition' => <condition to execute, as a string> * 'arguments' => <array oAn array of fields to update to an expression in case of a duplicate record.
/** * An array of values to update to. * * @var array */ protected $arguments = array()An array of values to update to.
/** * The condition object for this query. Condition handling is handled via * composition. * * @var DatabaseCondition */ protected $conditionThe condition object for this query. Condition handling is handled via composition.
/** * The table to update. * * @var string */ protected $tableThe table to update.

Funktionen & Methoden

NameBeschreibung
addConnectionInfoAdd database connection info for a given key/target.
getConnectionGets the connection object for the specified database key and target.
getConnectionInfoGets information on the specified database connection.
getLogRetrieve the queries logged on for given logging key.
ignoreTargetInstruct the system to temporarily ignore a given key/target.
isActiveConnectionDetermine if there is an active connection.
openConnectionOpen a connection to the server specified by the given key and target.
parseConnectionInfoProcess the configuration file for database information.
setActiveConnectionSet the active connection to the specified key.
startLogStart logging a given logging key on the specified connection.
arguments
compile
condition
conditions
countReturn the size of this conditional. This is part of the Countable interface.
isNotNull
isNull
mapConditionOperatorGets any special processing requirements for the condition operator.
where
__construct
__toString
commitThrows an exception to deny direct access to transaction commits.
databaseTypeReturns the type of the database being accessed.
defaultOptionsReturn the default query options for any given query.
deletePrepare and return a DELETE query object with the specified ID.
driverReturns the type of database driver.
escapeTableEscapes a table name string.
expandArgumentsExpand out shorthand placeholders.
generateTemporaryTableNameGenerate a temporary table name.
getLoggerGet the current logging object for this connection.
getTargetReturns the target this connection is associated with.
insertPrepare and return an INSERT query object with the specified ID.
inTransactionDetermine if there is an active transaction open.
makeSequenceNameCreate the appropriate sequence name for a given table and serial field.
mapConditionOperatorGets any special processing requirements for the condition operator.
mergePrepare and return a MERGE query object with the specified ID.
popTransactionDecreases the depth of transaction nesting, committing or rolling back if necessary.
prefixTablesAppend a database prefix to all tables in a query.
prepareQueryPrepare a query string and return the prepared statement.
pushTransactionIncreases the depth of transaction nesting.
queryExecutes a query string against the database.
queryRangeRuns a limited-range query on this database object.
queryTemporaryRuns a SELECT query and stores its results in a temporary table.
rollBackSchedule the current transaction for rollback.
schemaReturns a DatabaseSchema object for manipulating the schema of this database.
selectPrepare and return a SELECT query object with the specified ID.
setLoggerAssociate a logging object with this connection.
setTargetTell this connection object what its target value is.
startTransactionReturns a new DatabaseTransaction object on this connection.
supportsTransactionalDDLDetermine if this driver supports transactional DDL.
supportsTransactionsDetermine if this driver supports transactions.
truncatePrepare and return a TRUNCATE query object.
updatePrepare and return an UPDATE query object with the specified ID.
willRollBackDetermine if this transaction will roll back.
__construct
databaseType
distinctField@todo Remove this as soon as db_rewrite_sql() has been exterminated.
driver
mapConditionOperator
queryRange
queryTemporary
__construct
databaseType
distinctField@todo Remove this as soon as db_rewrite_sql() has been exterminated.
driver
mapConditionOperator
query
queryRange
queryTemporary
__construct
databaseType
distinctField@todo Remove this as soon as db_rewrite_sql() has been exterminated.
driver
mapConditionOperator
PDOPrepareNEVER CALL THIS FUNCTION: YOU MIGHT DEADLOCK YOUR PHP PROCESS.
prepareSQLite-specific implementation of DatabaseConnection::prepare().
prepareQuery
queryRange
queryTemporary
sqlFunctionConcatSQLite compatibility implementation for the CONCAT() SQL function.
sqlFunctionGreatestSQLite compatibility implementation for the GREATEST() SQL function.
sqlFunctionIfSQLite compatibility implementation for the IF() SQL function.
sqlFunctionRandSQLite compatibility implementation for the RAND() SQL function.
sqlFunctionSubstringSQLite compatibility implementation for the SUBSTRING() SQL function.
__construct
execute
fetchAllAssoc
fetchAllKeyed
fetchAssoc
fetchCol
fetchField
getQueryString
__construct
executeExecutes a prepared statement
fetchAllAssocReturns an entire result set as an associative array keyed by the named field.
fetchAllKeyedReturns the entire result set as a single associative array.
fetchAssocFetches the next row and returns it as an associative array.
fetchColReturns an entire single column of a result set as an indexed array.
fetchFieldReturn a single field out of the current
getQueryStringGet the query string of that statement.
rowCountReturns the number of rows affected by the last SQL statement.
currentReturn the current row formatted according to the current fetch style.
executeExecutes a prepared statement.
fetch
fetchAll
fetchAllAssoc
fetchAllKeyed
fetchAssoc
fetchCol
fetchField
fetchObject
getQueryStringReturn the object's SQL query string.
getStatementGrab a PDOStatement object from a given query and its arguments.
keyReturns the rendered local tasks. The default implementation renders them as tabs. Overridden to split the secondary tasks.
nextReturns the rendered local tasks. The default implementation renders them as tabs. Overridden to split the secondary tasks.
rewindReturns the rendered local tasks. The default implementation renders them as tabs. Overridden to split the secondary tasks.
rowCount
setFetchMode
throwPDOExceptionThrow a PDO Exception based on the last PDO error.
valid
__construct
execute
getStatementSQLite specific implementation of getStatement().
__construct
__destruct
db_affected_rowsDetermine the number of rows changed by the preceding query.
db_andReturns a new DatabaseCondition, set to "AND" all conditions together.
db_conditionReturns a new DatabaseCondition, set to the specified conjunction.
db_deleteReturns a new DeleteQuery object for the active database.
db_distinct_fieldWraps the given table.field entry with a DISTINCT(). The wrapper is added to the SELECT list entry of the given query and the resulting query is returned. This function only applies the wrapper if a DISTINCT doesn't already exist in the query.
db_driverRetrieve the name of the currently active database driver, such as "mysql" or "pgsql".
db_escape_tableRestrict a dynamic table, column or constraint name to safe characters.
db_fetch_array
db_fetch_object
db_insertReturns a new InsertQuery object for the active database.
db_is_activeDetermine if there is an active connection.
db_last_insert_idReturns the last insert id.
db_mergeReturns a new MergeQuery object for the active database.
db_orReturns a new DatabaseCondition, set to "OR" all conditions together.
db_placeholdersGenerate placeholders for an array of query arguments of a single type.
db_queryExecute an arbitrary query string against the active database.
db_query_rangeExecute an arbitrary query string against the active database, restricted to a specified range.
db_query_temporaryExecute a query string against the active database and save the result set to a temp table.
db_result
db_rewrite_sqlRewrites node, taxonomy and comment queries. Use it for listing queries. Do not use FROM table1, table2 syntax, use JOIN instead.
db_selectReturns a new SelectQuery object for the active database.
db_set_activeSets a new active database.
db_transactionReturns a new transaction object for the active database.
db_truncateReturns a new TruncateQuery object for the active database.
db_updateReturns a new UpdateQuery object for the active database.
db_xorReturns a new DatabaseCondition, set to "XOR" all conditions together.
arguments
compile
condition
conditions
execute
isNotNull
isNull
where
__construct
__toString
execute
delayFlag this query as being delay-safe or not.
executeExecutes the insert query.
fieldsAdd a set of field->value pairs to be inserted.
useDefaultsSpecify fields for which the database-defaults should be used.
valuesAdd another set of values to the query to be inserted.
__construct
__toString
execute
__toString
execute
__toString
execute
__toString
execute
expressionSpecify fields to be updated as an expression.
fieldsSet the field->value pairs to be merged into the table.
keySet the key field(s) to be used to insert or update into the table.
updateSpecify fields to update in case of a duplicate record.
updateExceptSpecify fields that should not be updated in case of a duplicate record.
__construct
__toString
execute
__toString
pager_queryPerform a paged database query.
executeRun the query against the database.
__construct
__toString__toString() magic method.
addMetaDataAdds additional metadata to the query.
addTagAdds a tag to a query.
getMetaDataRetrieves a given piece of metadata.
hasAllTagsDetermines if a given query has all specified tags.
hasAnyTagDetermines if a given query has any specified tag.
hasTagDetermines if a given query has a given tag.
argumentsGets a complete list of all values to insert into the prepared statement.
compileCompiles the saved conditions for later retrieval.
conditionHelper function to build most common conditional clauses.
conditionsGets a complete list of all conditions in this conditional clause.
isNotNullSet a condition that the specified field be NOT NULL.
isNullSet a condition that the specified field be NULL.
whereAdd an arbitrary WHERE clause to the query.
extendEnhance this object by wrapping it in an extender object.
addExpression
addField
addJoin
addMetaData
addTag
arguments
compile
condition
conditions
countQuery
distinct
execute
extend
fields
getArguments
getExpressions
getFields
getMetaData
getOrderBy
getTables
groupBy
hasAllTags
hasAnyTag
hasTag
having
havingArguments
havingCompile
havingCondition
havingConditions
havingIsNotNull
havingIsNull
innerJoin
isNotNull
isNull
join
leftJoin
orderBy
range
rightJoin
where
__clone
__construct
__toString
addExpression
addField
addJoin
addMetaData
addTag
arguments
compile
condition
conditions
countQuery
distinct
execute
extend
fields
getArguments
getExpressions
getFields
getMetaData
getOrderBy
getTables
groupBy
hasAllTags
hasAnyTag
hasTag
having
havingArguments
havingCompile
havingCondition
havingConditions
innerJoin
isNotNull
isNull
joinDefault Join against another table in the database.
leftJoin
orderBy
range
rightJoin
where
__callMagic override for undefined methods.
__clone
__construct
__toString
addExpressionAdds an expression to the list of "fields" to be SELECTed.
addFieldAdds a field to the list to be SELECTed.
addJoinJoin against another table in the database.
countQueryGet the equivalent COUNT query of this query as a new query object.
distinctSets this query to be DISTINCT.
fieldsAdd multiple fields from the same table to be SELECTed.
getArgumentsCompiles and returns an associative array of the arguments for this prepared statement.
getExpressionsReturns a reference to the expressions array for this query.
getFieldsReturns a reference to the fields array for this query.
getOrderByReturns a reference to the order by array for this query.
getTablesReturns a reference to the tables array for this query.
groupByGroups the result set by the specified field.
innerJoinInner Join against another table in the database.
joinDefault Join against another table in the database.
leftJoinLeft Outer Join against another table in the database.
orderByOrders the result set by a given field.
rangeRestricts a query to a given range in the result set.
rightJoinRight Outer Join against another table in the database.
__cloneClone magic method.
tablesort_sqlCreate an SQL sort clause.
compile
execute
__construct
__toString
__toString
arguments
compile
condition
conditions
execute
expressionSpecify fields to be updated as an expression.
fieldsAdd a set of field->value pairs to be updated.
isNotNull
isNull
where
__construct
__toString
execute
execute
removeFieldsInConditionHelper function that removes the fields that are already in a condition.
update_sqlPerform an SQL query and return success or failure.
_db_check_install_neededRedirect the user to the installation script if Drupal has not been installed yet (i.e., if no $databases array has been defined in the settings file) and we are not already there. Otherwise, do nothing.
_db_query_process_argsBackward-compatibility utility.
_db_rewrite_sqlHelper function for db_rewrite_sql.

Interfaces

NameBeschreibung
DatabaseStatementInterfaceA prepared statement.
QueryAlterableInterfaceInterface for a query that can be manipulated via an alter hook.
QueryConditionInterfaceInterface for a conditional clause in a query.
QueryExtendableInterfaceInterface for extendable query objects.
SelectQueryInterfaceInterface definition for a Select Query object.

includes/database/database.inc, line 9

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen