MediaWiki  master
Wikimedia\Rdbms\DatabaseFactory Class Reference

Constructs Database objects. More...

Public Member Functions

 attributesFromType ( $dbType, $driver=null)
 
 create ( $type, $params=[], $connect=Database::NEW_CONNECTED)
 Construct a Database subclass instance given a database type and parameters. More...
 

Protected Member Functions

 getClass ( $dbType, $driver=null)
 

Detailed Description

Constructs Database objects.

Since
1.39

Definition at line 33 of file DatabaseFactory.php.

Member Function Documentation

◆ attributesFromType()

Wikimedia\Rdbms\DatabaseFactory::attributesFromType (   $dbType,
  $driver = null 
)
Parameters
string$dbTypeA possible DB type (sqlite, mysql, postgres,...)
string | null$driverOptional name of a specific DB client driver
Returns
array Map of (Database::ATTR_* constant => value) for all such constants
Exceptions
DBUnexpectedError

Definition at line 140 of file DatabaseFactory.php.

References Wikimedia\Rdbms\DatabaseFactory\getClass().

◆ create()

Wikimedia\Rdbms\DatabaseFactory::create (   $type,
  $params = [],
  $connect = Database::NEW_CONNECTED 
)

Construct a Database subclass instance given a database type and parameters.

This also connects to the database immediately upon object construction

Parameters
string$typeA possible DB type (sqlite, mysql, postgres,...)
array$paramsParameter map with keys:
  • host : The hostname of the DB server
  • user : The name of the database user the client operates under
  • password : The password for the database user
  • dbname : The name of the database to use where queries do not specify one. The database must exist or an error might be thrown. Setting this to the empty string will avoid any such errors and make the handle have no implicit database scope. This is useful for queries like SHOW STATUS, CREATE DATABASE, or DROP DATABASE. Note that a "database" in Postgres is rougly equivalent to an entire MySQL server. This the domain in which user names and such are defined, e.g. users are database-specific in Postgres.
  • schema : The database schema to use (if supported). A "schema" in Postgres is roughly equivalent to a "database" in MySQL. Note that MySQL and SQLite do not use schemas.
  • tablePrefix : Optional table prefix that is implicitly added on to all table names recognized in queries. This can be used in place of schemas for handle site farms.
  • flags : Optional bit field of DBO_* constants that define connection, protocol, buffering, and transaction behavior. It is STRONGLY adviced to leave the DBO_DEFAULT flag in place UNLESS this this database simply acts as a key/value store.
  • driver: Optional name of a specific DB client driver. For MySQL, there is only the 'mysqli' driver; the old one 'mysql' has been removed.
  • variables: Optional map of session variables to set after connecting. This can be used to adjust lock timeouts or encoding modes and the like.
  • topologyRole: Optional IDatabase::ROLE_* constant for the server.
  • lbInfo: Optional map of field/values for the managing load balancer instance. The "master" and "replica" fields are used to flag the replication role of this database server and whether methods like getLag() should actually issue queries.
  • topologicalPrimaryConnRef: lazy-connecting IDatabase handle to the most authoritative primary database server for the cluster that this database belongs to. This handle is used for replication status purposes. This is generally managed by LoadBalancer.
  • connLogger: Optional PSR-3 logger interface instance.
  • queryLogger: Optional PSR-3 logger interface instance.
  • profiler : Optional callback that takes a section name argument and returns a ScopedCallback instance that ends the profile section in its destructor. These will be called in query(), using a simplified version of the SQL that also includes the agent as a SQL comment.
  • trxProfiler: Optional TransactionProfiler instance.
  • errorLogger: Optional callback that takes an Exception and logs it.
  • deprecationLogger: Optional callback that takes a string and logs it.
  • cliMode: Whether to consider the execution context that of a CLI script.
  • agent: Optional name used to identify the end-user in query profiling/logging.
  • serverName: Optional human-readable server name
  • srvCache: Optional BagOStuff instance to an APC-style cache.
  • nonNativeInsertSelectBatchSize: Optional batch size for non-native INSERT SELECT.
int$connectOne of the class constants (NEW_CONNECTED, NEW_UNCONNECTED) [optional]
Returns
Database|null If the database driver or extension cannot be found
Exceptions
InvalidArgumentExceptionIf the database driver or extension cannot be found

Definition at line 87 of file DatabaseFactory.php.

References $type, and Wikimedia\Rdbms\DatabaseFactory\getClass().

◆ getClass()

Wikimedia\Rdbms\DatabaseFactory::getClass (   $dbType,
  $driver = null 
)
protected
Parameters
string$dbTypeA possible DB type (sqlite, mysql, postgres,...)
string | null$driverOptional name of a specific DB client driver
Returns
string Database subclass name to use
Exceptions
InvalidArgumentException

Definition at line 161 of file DatabaseFactory.php.

Referenced by Wikimedia\Rdbms\DatabaseFactory\attributesFromType(), and Wikimedia\Rdbms\DatabaseFactory\create().


The documentation for this class was generated from the following file: