MediaWiki REL1_40
|
A database connection without write operations. More...
Inherits Wikimedia\Rdbms\Platform\ISQLPlatform, Wikimedia\Rdbms\Database\DbQuoter, and Wikimedia\Rdbms\Database\IDatabaseFlags.
Inherited by Wikimedia\Rdbms\IDatabase.
Public Member Functions | |
__toString () | |
Get a debugging string that mentions the database type, the ID of this instance, and the ID of any underlying connection resource or driver object if one is present. | |
close ( $fname=__METHOD__) | |
Close the database connection. | |
databasesAreIndependent () | |
Returns true if DBs are assumed to be on potentially different servers. | |
dbSchema ( $schema=null) | |
Get/set the db schema. | |
decodeBlob ( $b) | |
Some DBMSs return a special placeholder object representing blob fields in result objects. | |
encodeBlob ( $b) | |
Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strings to be inserted. | |
estimateRowCount ( $tables, $var=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Estimate the number of rows in dataset. | |
getDBname () | |
Get the current database name; null if there isn't one. | |
getDomainID () | |
Return the currently selected domain ID. | |
getLag () | |
Get the amount of replication lag for this database server. | |
getReplicaPos () | |
Get the replication position of this replica DB. | |
getServer () | |
Get the hostname or IP address of the server. | |
getServerInfo () | |
Get a human-readable string describing the current software version. | |
getServerName () | |
Get the readable name for the server. | |
getServerVersion () | |
A string describing the current software version, like from mysql_get_server_info() | |
getSessionLagStatus () | |
Get the replica server lag when the current transaction started or a general lag estimate if not transaction is active. | |
getSoftwareLink () | |
Returns a wikitext style link to the DB's website (e.g. | |
getType () | |
Get the RDBMS type of the server (e.g. | |
isOpen () | |
lastErrno () | |
Get the RDBMS-specific error code from the last attempted query statement. | |
lastError () | |
Get the RDBMS-specific error description from the last attempted query statement. | |
lastQuery () | |
Get the last query that sent on account of IDatabase::query() | |
newSelectQueryBuilder () | |
Create an empty SelectQueryBuilder which can be used to run queries against this connection. | |
ping () | |
Ping the server and try to reconnect if it there is no connection. | |
primaryPosWait (DBPrimaryPos $pos, $timeout) | |
Wait for the replica server to catch up to a given primary server position. | |
select ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Execute a SELECT query constructed using the various parameters provided. | |
selectDomain ( $domain) | |
Set the current domain (database, schema, and table prefix) | |
selectField ( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
A SELECT wrapper which returns a single field from a single result row. | |
selectFieldValues ( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
A SELECT wrapper which returns a list of single field values from result rows. | |
selectRow ( $table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[]) | |
Wrapper to IDatabase::select() that only fetches one row (via LIMIT) | |
selectRowCount ( $tables, $var=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Get the number of rows in dataset. | |
tablePrefix ( $prefix=null) | |
Get/set the table prefix. | |
wasConnectionLoss () | |
Determines if the last query error was due to a dropped connection. | |
wasDeadlock () | |
Determines if the last failure was due to a deadlock. | |
wasErrorReissuable () | |
Determines if the last query error was due to something outside of the query itself. | |
wasLockTimeout () | |
Determines if the last failure was due to a lock timeout. | |
wasReadOnlyError () | |
Determines if the last failure was due to the database being read-only. | |
Public Member Functions inherited from Wikimedia\Rdbms\Platform\ISQLPlatform | |
addIdentifierQuotes ( $s) | |
Escape a SQL identifier (e.g. | |
anyChar () | |
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query. | |
anyString () | |
Returns a token for buildLike() that denotes a '' to be used in a LIKE query. | |
bitAnd ( $fieldLeft, $fieldRight) | |
bitNot ( $field) | |
bitOr ( $fieldLeft, $fieldRight) | |
buildComparison (string $op, array $conds) | |
Build a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g. | |
buildConcat ( $stringList) | |
Build a concatenation list to feed into a SQL query. | |
buildExcludedValue ( $column) | |
Build a reference to a column value from the conflicting proposed upsert() row. | |
buildGreatest ( $fields, $values) | |
Build a GREATEST function statement comparing columns/values. | |
buildGroupConcatField ( $delim, $table, $field, $conds='', $join_conds=[]) | |
Build a GROUP_CONCAT or equivalent statement for a query. | |
buildIntegerCast ( $field) | |
buildLeast ( $fields, $values) | |
Build a LEAST function statement comparing columns/values. | |
buildLike ( $param,... $params) | |
LIKE statement wrapper. | |
buildSelectSubquery ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery. | |
buildStringCast ( $field) | |
buildSubString ( $input, $startPosition, $length=null) | |
Build a SUBSTRING function. | |
conditional ( $cond, $caseTrueExpression, $caseFalseExpression) | |
Returns an SQL expression for a simple conditional. | |
decodeExpiry ( $expiry, $format=TS_MW) | |
Decode an expiry time into a DBMS independent format. | |
encodeExpiry ( $expiry) | |
Encode an expiry time into the DBMS dependent format. | |
factorConds ( $condsArray) | |
Given an array of condition arrays representing an OR list of AND lists, for example: | |
getInfinity () | |
Find out when 'infinity' is. | |
getTableAliases () | |
Return current table aliases. | |
implicitOrderby () | |
Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1. | |
limitResult ( $sql, $limit, $offset=false) | |
Construct a LIMIT query with optional offset. | |
makeList (array $a, $mode=self::LIST_COMMA) | |
Makes an encoded list of strings from an array. | |
makeWhereFrom2d ( $data, $baseKey, $subKey) | |
Build a partial where clause from a 2-d array such as used for LinkBatch. | |
selectSQLText ( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Take the same arguments as IDatabase::select() and return the SQL it would use. | |
setIndexAliases (array $aliases) | |
Convert certain index names to alternative names before querying the DB. | |
setSchemaVars ( $vars) | |
Set schema variables to be used when streaming commands from SQL files or stdin. | |
setTableAliases (array $aliases) | |
Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name. | |
strreplace ( $orig, $old, $new) | |
Returns a SQL expression for simple string replacement (e.g. | |
tableName ( $name, $format='quoted') | |
Format a table name ready for use in constructing an SQL query. | |
tableNames (... $tables) | |
Fetch a number of table names into an associative array. | |
tableNamesN (... $tables) | |
Fetch a number of table names into a zero-indexed numerical array. | |
timestamp ( $ts=0) | |
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS. | |
timestampOrNull ( $ts=null) | |
Convert a timestamp in one of the formats accepted by ConvertibleTimestamp to the format used for inserting into timestamp fields in this DBMS. | |
unionConditionPermutations ( $table, $vars, array $permute_conds, $extra_conds='', $fname=__METHOD__, $options=[], $join_conds=[]) | |
Construct a UNION query for permutations of conditions. | |
unionQueries ( $sqls, $all) | |
Construct a UNION query. | |
unionSupportsOrderAndLimit () | |
Determine if the RDBMS supports ORDER BY and LIMIT for separate subqueries within UNION. | |
Public Member Functions inherited from Wikimedia\Rdbms\Database\DbQuoter | |
addQuotes ( $s) | |
Escape and quote a raw value string for use in a SQL query. | |
Public Member Functions inherited from Wikimedia\Rdbms\Database\IDatabaseFlags | |
clearFlag ( $flag, $remember=self::REMEMBER_NOTHING) | |
Clear a flag for this connection. | |
getFlag ( $flag) | |
Returns a boolean whether the flag $flag is set for this connection. | |
restoreFlags ( $state=self::RESTORE_PRIOR) | |
Restore the flags to their prior state before the last setFlag/clearFlag call. | |
setFlag ( $flag, $remember=self::REMEMBER_NOTHING) | |
Set a flag for this connection. | |
Additional Inherited Members | |
Public Attributes inherited from Wikimedia\Rdbms\Platform\ISQLPlatform | |
const | QUERY_PSEUDO_PERMANENT = 2 |
Track a TEMPORARY table CREATE as if it was for a permanent table (for testing) | |
A database connection without write operations.
Definition at line 33 of file IReadableDatabase.php.
Wikimedia\Rdbms\IReadableDatabase::__toString | ( | ) |
Get a debugging string that mentions the database type, the ID of this instance, and the ID of any underlying connection resource or driver object if one is present.
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::close | ( | $fname = __METHOD__ | ) |
Close the database connection.
This should only be called after any transactions have been resolved, aside from read-only automatic transactions (assuming no callbacks are registered). If a transaction is still open anyway, it will be rolled back.
string | $fname | Caller name |
DBError |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\LoadBalancer\closeConnection().
Wikimedia\Rdbms\IReadableDatabase::databasesAreIndependent | ( | ) |
Returns true if DBs are assumed to be on potentially different servers.
In systems like mysql/mariadb, different databases can easily be referenced on a single connection merely by name, even in a single query via JOIN. On the other hand, Postgres treats databases as logically separate, with different database users, requiring special mechanisms like postgres_fdw to "mount" foreign DBs. This is true even among DBs on the same server. Changing the selected database via selectDomain() requires a new connection.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::dbSchema | ( | $schema = null | ) |
Get/set the db schema.
string | null | $schema | The database schema to set, or omitted to leave it unchanged |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::decodeBlob | ( | $b | ) |
Some DBMSs return a special placeholder object representing blob fields in result objects.
Pass the object through this function to return the original string.
string | Blob | $b |
DBError |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Referenced by ArchivedFile\loadMetadataFromDbFieldValue(), and LocalFile\loadMetadataFromDbFieldValue().
Wikimedia\Rdbms\IReadableDatabase::encodeBlob | ( | $b | ) |
Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strings to be inserted.
To insert into such a field, pass the data through this function before passing it to IDatabase::insert().
string | $b |
DBError |
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Referenced by ArchivedFile\getMetadataForDb(), LocalFile\getMetadataForDb(), and LCStoreDB\set().
Wikimedia\Rdbms\IReadableDatabase::estimateRowCount | ( | $tables, | |
$var = ' *', | |||
$conds = '', | |||
$fname = __METHOD__, | |||
$options = [], | |||
$join_conds = [] ) |
Estimate the number of rows in dataset.
MySQL allows you to estimate the number of rows that would be returned by a SELECT query, using EXPLAIN SELECT. The estimate is provided using index cardinality statistics, and is notoriously inaccurate, especially when large numbers of rows have recently been added or deleted.
For DBMSs that don't support fast result size estimation, this function will actually perform the SELECT COUNT(*).
Takes the same arguments as IDatabase::select().
New callers should use newSelectQueryBuilder
with SelectQueryBuilder::estimateRowCount
instead, which is more readable and less error-prone.
string | string[] | $tables | Table name(s) |
string | $var | Column for which NULL values are not counted [default "*"] |
array | string | $conds | Filters on the table |
string | $fname | Function name for profiling |
array | $options | Options for select |
array | string | $join_conds | Join conditions |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::getDBname | ( | ) |
Get the current database name; null if there isn't one.
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\Replication\ReplicationReporter\getLogContext().
Wikimedia\Rdbms\IReadableDatabase::getDomainID | ( | ) |
Return the currently selected domain ID.
Null components (database/schema) might change once a connection is established
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\LoadBalancer\closeConnection(), MediaWiki\Deferred\LinksUpdate\LinksTable\doWrites(), Wikimedia\Rdbms\LoadBalancer\getConnLogContext(), MediaWiki\User\ActorMigrationBase\getInsertValues(), MediaWiki\User\ActorMigrationBase\getInsertValuesWithTempTable(), MediaWiki\User\ActorMigrationBase\getWhere(), MediaWiki\Title\Title\invalidateCache(), Wikimedia\Rdbms\LBFactorySingle\newFromConnection(), Wikimedia\Rdbms\LoadBalancerSingle\newFromConnection(), MediaWiki\ResourceLoader\WikiModule\preloadTitleInfo(), and Wikimedia\Rdbms\TransactionManager\transactionWritingOut().
Wikimedia\Rdbms\IReadableDatabase::getLag | ( | ) |
Get the amount of replication lag for this database server.
Callers should avoid using this method while a transaction is active
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::getReplicaPos | ( | ) |
Get the replication position of this replica DB.
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::getServer | ( | ) |
Get the hostname or IP address of the server.
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::getServerInfo | ( | ) |
Get a human-readable string describing the current software version.
Use getServerVersion() to get machine-friendly information.
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::getServerName | ( | ) |
Get the readable name for the server.
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\DBQueryError\__construct(), Wikimedia\Rdbms\Replication\MysqlReplicationReporter\getApproximateLagStatus(), Wikimedia\Rdbms\LoadBalancer\getConnLogContext(), Wikimedia\Rdbms\Replication\ReplicationReporter\getLogContext(), Wikimedia\Rdbms\Replication\MysqlReplicationReporter\getServerId(), Wikimedia\Rdbms\Replication\MysqlReplicationReporter\getServerUUID(), and Wikimedia\Rdbms\TransactionManager\transactionWritingOut().
Wikimedia\Rdbms\IReadableDatabase::getServerVersion | ( | ) |
A string describing the current software version, like from mysql_get_server_info()
Implemented in Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\Database\getServerInfo(), and DatabaseInstaller\meetsMinimumRequirement().
Wikimedia\Rdbms\IReadableDatabase::getSessionLagStatus | ( | ) |
Get the replica server lag when the current transaction started or a general lag estimate if not transaction is active.
This is useful when transactions might use snapshot isolation (e.g. REPEATABLE-READ in innodb), so the "real" lag of that data is this lag plus transaction duration. If they don't, it is still safe to be pessimistic. In AUTOCOMMIT mode, this still gives an indication of the staleness of subsequent reads.
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::getSoftwareLink | ( | ) |
Returns a wikitext style link to the DB's website (e.g.
"[https://www.mysql.com/ MySQL]")
Should at least contain plain text, if for some reason your database has no website.
Implemented in Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Referenced by MysqlInstaller\meetsMinimumRequirement().
Wikimedia\Rdbms\IReadableDatabase::getType | ( | ) |
Get the RDBMS type of the server (e.g.
"mysql", "sqlite")
Implemented in Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\LoadBalancerSingle\__construct(), Wikimedia\Rdbms\SelectQueryBuilder\connection(), Wikimedia\Rdbms\UpdateQueryBuilder\connection(), SqlBagOStuff\createTables(), DatabaseUpdater\newForDB(), and DatabaseUpdater\patchPath().
Wikimedia\Rdbms\IReadableDatabase::isOpen | ( | ) |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::lastErrno | ( | ) |
Get the RDBMS-specific error code from the last attempted query statement.
Implemented in Wikimedia\Rdbms\DatabaseMysqli, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\DatabaseMysqlBase\wasDeadlock(), Wikimedia\Rdbms\DatabaseMysqlBase\wasLockTimeout(), and Wikimedia\Rdbms\DatabaseMysqlBase\wasReadOnlyError().
Wikimedia\Rdbms\IReadableDatabase::lastError | ( | ) |
Get the RDBMS-specific error description from the last attempted query statement.
Implemented in Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::lastQuery | ( | ) |
Get the last query that sent on account of IDatabase::query()
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::newSelectQueryBuilder | ( | ) |
Create an empty SelectQueryBuilder which can be used to run queries against this connection.
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by MediaWiki\CommentStore\CommentStoreBase\createComment(), JobQueueDB\doBatchPushInternal(), MediaWiki\ResourceLoader\WikiModule\fetchTitleInfo(), ChangeTags\getTagsWithData(), and LocalFileMoveBatch\verifyDBUpdates().
Wikimedia\Rdbms\IReadableDatabase::ping | ( | ) |
Ping the server and try to reconnect if it there is no connection.
Implemented in Wikimedia\Rdbms\Database.
Wikimedia\Rdbms\IReadableDatabase::primaryPosWait | ( | DBPrimaryPos | $pos, |
$timeout ) |
Wait for the replica server to catch up to a given primary server position.
Note that this does not start any new transactions.
Callers might want to flush any existing transaction before invoking this method. Upon success, this assures that replica server queries will reflect all changes up to the given position, without interference from prior REPEATABLE-READ snapshots.
DBPrimaryPos | $pos | |
int | $timeout | The maximum number of seconds to wait for synchronisation |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by Wikimedia\Rdbms\LoadBalancer\waitForPrimaryPos().
Wikimedia\Rdbms\IReadableDatabase::select | ( | $table, | |
$vars, | |||
$conds = '', | |||
$fname = __METHOD__, | |||
$options = [], | |||
$join_conds = [] ) |
Execute a SELECT query constructed using the various parameters provided.
New callers should use newSelectQueryBuilder
with SelectQueryBuilder::fetchResultSet
instead, which is more readable and less error-prone.
string | array | $table | Table name(s) |
May be either an array of table names, or a single string holding a table name. If an array is given, table aliases can be specified, for example:
[ 'a' => 'user' ]
This includes the user table in the query, with the alias "a" available for use in field names (e.g. a.user_name).
A derived table, defined by the result of selectSQLText(), requires an alias key and a Subquery instance value which wraps the SQL query, for example:
[ 'c' => new Subquery( 'SELECT ...' ) ]
Joins using parentheses for grouping (since MediaWiki 1.31) may be constructed using nested arrays. For example,
[ 'tableA', 'nestedB' => [ 'tableB', 'b2' => 'tableB2' ] ]
along with $join_conds
like
[ 'b2' => [ 'JOIN', 'b_id = b2_id' ], 'nestedB' => [ 'LEFT JOIN', 'b_a = a_id' ] ]
will produce SQL something like
FROM tableA LEFT JOIN (tableB JOIN tableB2 AS b2 ON (b_id = b2_id)) ON (b_a = a_id)
All of the table names given here are automatically run through Database::tableName(), which causes the table prefix (if any) to be added, and various other table name mappings to be performed.
Do not use untrusted user input as a table name. Alias names should not have characters outside of the Basic multilingual plane.
string | array | $vars | Field name(s) |
May be either a field name or an array of field names. The field names can be complete fragments of SQL, for direct inclusion into the SELECT query. If an array is given, field aliases can be specified, for example:
[ 'maxrev' => 'MAX(rev_id)' ]
This includes an expression with the alias "maxrev" in the query.
If an expression is given, care must be taken to ensure that it is DBMS-independent.
Untrusted user input must not be passed to this parameter.
string | array | $conds |
May be either a string containing a single condition, or an array of conditions. If an array is given, the conditions constructed from each element are combined with AND.
Array elements may take one of two forms:
Note that expressions are often DBMS-dependent in their syntax. DBMS-independent wrappers are provided for constructing several types of expression commonly used in condition queries. See:
Untrusted user input is safe in the values of string keys, however untrusted input must not be used in the array key names or in the values of numeric keys. Escaping of untrusted input used in values of numeric keys should be done via IDatabase::addQuotes()
Use an empty array, string, or IDatabase::ALL_ROWS to select all rows.
You can put simple join conditions here, but this is strongly discouraged. Instead of
// $conds... 'rev_actor = actor_id',
use (see below for $join_conds):
// $join_conds... 'actor' => [ 'JOIN', 'rev_actor = actor_id' ],
string | $fname | Caller function name |
string | array | $options | Query options |
Optional: Array of query options. Boolean options are specified by including them in the array as a string value with a numeric key, for example:
[ 'FOR UPDATE' ]
The supported options are:
And also the following boolean MySQL extensions, see the MySQL manual for documentation:
string | array | $join_conds | Join conditions |
Optional associative array of table-specific join conditions. Simple conditions can also be specified in the regular $conds, but this is strongly discouraged in favor of the more explicit syntax here.
The key of the array contains the table name or alias. The value is an array with two elements, numbered 0 and 1. The first gives the type of join, the second is the same as the $conds parameter. Thus it can be an SQL fragment, or an array where the string keys are equality and the numeric keys are SQL fragments all AND'd together. For example:
[ 'page' => [ 'LEFT JOIN', 'page_latest=rev_id' ] ]
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by RefreshImageMetadata\execute(), and MediaWiki\Revision\RevisionStore\userWasLastToEdit().
Wikimedia\Rdbms\IReadableDatabase::selectDomain | ( | $domain | ) |
Set the current domain (database, schema, and table prefix)
This will throw an error for some database types if the database is unspecified
This should only be called by a load balancer or if the handle is not attached to one
string | DatabaseDomain | $domain |
DBConnectionError | If databasesAreIndependent() is true and connection change fails |
DBError | On query error, if domain changes are disallowed, or the domain is invalid |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::selectField | ( | $table, | |
$var, | |||
$cond = '', | |||
$fname = __METHOD__, | |||
$options = [], | |||
$join_conds = [] ) |
A SELECT wrapper which returns a single field from a single result row.
If no result rows are returned from the query, false is returned.
New callers should use newSelectQueryBuilder
with SelectQueryBuilder::fetchField
instead, which is more readable and less error-prone.
string | array | $table | Table name. { |
string | array | $var | The field name to select. This must be a valid SQL fragment: do not use unvalidated user input. Can be an array, but must contain exactly 1 element then. { |
string | array | $cond | The condition array. { |
string | $fname | The function name of the caller. |
string | array | $options | The query options. { |
string | array | $join_conds | The query join conditions. { |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by User\addToDatabase(), MediaWiki\Revision\RevisionStore\getTimestampFromId(), and MediaWiki\Revision\RevisionStore\newNullRevision().
Wikimedia\Rdbms\IReadableDatabase::selectFieldValues | ( | $table, | |
$var, | |||
$cond = '', | |||
$fname = __METHOD__, | |||
$options = [], | |||
$join_conds = [] ) |
A SELECT wrapper which returns a list of single field values from result rows.
If no result rows are returned from the query, an empty array is returned.
New callers should use newSelectQueryBuilder
with SelectQueryBuilder::fetchFieldValues
instead, which is more readable and less error-prone.
string | array | $table | Table name. { |
string | $var | The field name to select. This must be a valid SQL fragment: do not use unvalidated user input. |
string | array | $cond | The condition array. { |
string | $fname | The function name of the caller. |
string | array | $options | The query options. { |
string | array | $join_conds | The query join conditions. { |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by PurgeJobUtils\invalidatePages(), MediaWiki\Block\DatabaseBlockStore\purgeExpiredBlocks(), and MediaWiki\Title\Title\purgeExpiredRestrictions().
Wikimedia\Rdbms\IReadableDatabase::selectRow | ( | $table, | |
$vars, | |||
$conds, | |||
$fname = __METHOD__, | |||
$options = [], | |||
$join_conds = [] ) |
Wrapper to IDatabase::select() that only fetches one row (via LIMIT)
If the query returns no rows, false is returned.
This method is convenient for fetching a row based on a unique key condition.
New callers should use newSelectQueryBuilder
with SelectQueryBuilder::fetchRow
instead, which is more readable and less error-prone.
string | array | $table | Table name |
string | array | $vars | Field names |
string | array | $conds | Conditions |
string | $fname | Caller function name |
string | array | $options | Query options |
array | string | $join_conds | Join conditions |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by MediaWiki\Revision\RevisionStore\countRevisionsByPageId(), Wikimedia\Rdbms\Replication\MysqlReplicationReporter\getReplicationSafetyInfo(), and DatabaseLogEntry\newFromId().
Wikimedia\Rdbms\IReadableDatabase::selectRowCount | ( | $tables, | |
$var = ' *', | |||
$conds = '', | |||
$fname = __METHOD__, | |||
$options = [], | |||
$join_conds = [] ) |
Get the number of rows in dataset.
This is useful when trying to do COUNT(*) but with a LIMIT for performance.
Takes the same arguments as IDatabase::select().
New callers should use newSelectQueryBuilder
with SelectQueryBuilder::fetchRowCount
instead, which is more readable and less error-prone.
string | string[] | $tables | Table name(s) |
string | $var | Column for which NULL values are not counted [default "*"] |
array | string | $conds | Filters on the table |
string | $fname | Function name for profiling |
array | $options | Options for select |
array | $join_conds | Join conditions (since 1.27) |
DBError | If an error occurs, { |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::tablePrefix | ( | $prefix = null | ) |
Get/set the table prefix.
string | null | $prefix | The table prefix to set, or omitted to leave it unchanged |
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Referenced by CloneDatabase\__construct().
Wikimedia\Rdbms\IReadableDatabase::wasConnectionLoss | ( | ) |
Determines if the last query error was due to a dropped connection.
Note that during a connection loss, the prior transaction will have been lost
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::wasDeadlock | ( | ) |
Determines if the last failure was due to a deadlock.
Note that during a deadlock, the prior transaction will have been lost
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::wasErrorReissuable | ( | ) |
Determines if the last query error was due to something outside of the query itself.
Note that the transaction may have been lost, discarding prior writes and results
Implemented in Wikimedia\Rdbms\Database, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::wasLockTimeout | ( | ) |
Determines if the last failure was due to a lock timeout.
Note that during a lock wait timeout, the prior transaction will have been lost
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabasePostgres, and Wikimedia\Rdbms\DBConnRef.
Wikimedia\Rdbms\IReadableDatabase::wasReadOnlyError | ( | ) |
Determines if the last failure was due to the database being read-only.
Implemented in Wikimedia\Rdbms\Database, Wikimedia\Rdbms\DatabaseMysqlBase, Wikimedia\Rdbms\DatabaseSqlite, and Wikimedia\Rdbms\DBConnRef.
Referenced by LCStoreDB\finishWrite().