36 $this->cliMode = isset( $opts[
'cliMode'] ) ? $opts[
'cliMode'] :
true;
37 $this->connLogger = new \Psr\Log\NullLogger();
38 $this->queryLogger = new \Psr\Log\NullLogger();
39 $this->errorLogger =
function ( Exception
$e ) {
40 wfWarn( get_class(
$e ) .
": {$e->getMessage()}" );
50 $lastSqls = implode(
'; ', $this->lastSqls );
64 $this->nextResult =
$res;
69 $this->lastSqls[] = trim( preg_replace(
70 '/\s{2,}(?=FROM|WHERE|GROUP BY|ORDER BY|LIMIT)|(?<=SELECT|INSERT|UPDATE)\s{2,}/',
76 if ( substr(
$fname, 0, strlen( $this->testName ) ) !== $this->testName ) {
77 throw new MWException(
'function name does not start with test class. ' .
78 $fname .
' vs. ' . $this->testName .
'. ' .
79 'Please provide __METHOD__ to database methods.' );
85 return str_replace(
"'",
"\'",
$s );
93 public function query( $sql,
$fname =
'', $tempIgnore =
false ) {
97 return parent::query( $sql,
$fname, $tempIgnore );
101 $tableRaw = $this->
tableName( $table,
'raw' );
102 if ( isset( $this->mSessionTempTables[$tableRaw] ) ) {
108 return in_array( $table, (
array)$this->tablesExists );
113 return parent::nativeReplace( $table, $rows,
$fname );
120 function open( $server, $user, $password, $dbName ) {
188 function ping( &$rtt =
null ) {
199 $this->nextResult = [];
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Helper for testing the methods from the Database class.
numFields( $res)
Get the number of fields in a result object.
array $nextResult
List of row arrays.
getSoftwareLink()
Returns a wikitext link to the DB's website, e.g., return "[http://www.mysql.com/ MySQL]"; Should at ...
addIdentifierQuotes( $s)
Quotes an identifier using backticks or "double quotes" depending on the database type.
strencode( $s)
Wrapper for addslashes()
ping(&$rtt=null)
Ping the server and try to reconnect if it there is no connection.
doQuery( $sql)
The DBMS-dependent part of query()
indexInfo( $table, $index, $fname='Database::indexInfo')
Get information about an index into an object.
nativeReplace( $table, $rows, $fname)
REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE statement.
numRows( $res)
Get the number of rows in a result object.
getServerVersion()
A string describing the current software version, like from mysql_get_server_info().
setExistingTables( $tablesExists)
query( $sql, $fname='', $tempIgnore=false)
Run an SQL query and return the result.
closeConnection()
Closes underlying database connection.
fetchRow( $res)
Fetch the next row from the given result object, in associative array form.
affectedRows()
Get the number of rows affected by the last write query.
__construct( $testName, array $opts=[])
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
fieldName( $res, $n)
Get a field name in a result object.
fetchObject( $res)
Fetch the next row from the given result object, in object form.
getLastSqls()
Returns SQL queries grouped by '; ' Clear the list of queries that have been done so far.
lastError()
Get a description of the last error.
getServerInfo()
A string describing the current software version, and possibly other details in a user-friendly way.
dataSeek( $res, $row)
Change the position of the cursor in a result object.
tableExists( $table, $fname=__METHOD__)
Query whether a given table exists.
$testName
CLASS of the test suite, used to determine, if the function name is passed every time to query()
open( $server, $user, $password, $dbName)
Open a connection to the database.
$tablesExists
Array of tables to be considered as existing by tableExist() Use setExistingTables() to alter.
fieldInfo( $table, $field)
mysql_fetch_field() wrapper Returns false if the field doesn't exist
lastErrno()
Get the last error number.
insertId()
Get the inserted value of an auto-increment row.
checkFunctionName( $fname)
isOpen()
Is a connection to the database open?
$lastSqls
Array of lastSqls passed to query(), This is an array since some methods in Database can do more than...
Relational database abstraction object.
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Stub profiler that does nothing.
Helper class that detects high-contention DB queries via profiling calls.
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for tableName() and addQuotes(). You will need both of them. ------------------------------------------------------------------------ Basic query optimisation ------------------------------------------------------------------------ MediaWiki developers who need to write DB queries should have some understanding of databases and the performance issues associated with them. Patches containing unacceptably slow features will not be accepted. Unindexed queries are generally not welcome in MediaWiki
the array() calling protocol came about after MediaWiki 1.4rc1.
returning false will NOT prevent logging $e
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php