return new DatabaseMysql( $server, $user, $password, $dbName, $flags );
}
+ /**
+ * Given a DB type, construct the name of the appropriate child class of
+ * DatabaseBase. This is designed to replace all of the manual stuff like:
+ * $class = 'Database' . ucfirst( strtolower( $type ) );
+ * as well as validate against the canonical list of DB types we have
+ *
+ * @param $dbType String A possible DB type
+ * @return DatabaseBase subclass or null
+ */
+ public final static function classFromType( $dbType ) {
+ $canonicalDBTypes = array(
+ 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql', 'ibm_db2'
+ );
+ $dbType = strtolower( $dbType );
+ if( in_array( $dbType, $canonicalDBTypes ) ) {
+ return 'Database' . ucfirst( $dbType );
+ } else {
+ return null;
+ }
+ }
+
protected function installErrorHandler() {
$this->mPHPError = false;
$this->htmlErrors = ini_set( 'html_errors', '0' );
}
# Get class for this database type
- $class = 'Database' . ucfirst( $type );
+ $class = DatabaseBase::classFromType( $type );
# Create object
wfDebug( "Connecting to $host $dbname...\n" );
private function initFromCond( $cond ) {
global $wgExternalAuthConf;
- $class = 'Database' . $wgExternalAuthConf['DBtype'];
+ $class = DatabaseBase::classFromType( $wgExternalAuthConf['DBtype'] )
$this->mDb = new $class(
$wgExternalAuthConf['DBserver'],
$wgExternalAuthConf['DBuser'],
function getMasterDB() {
if ( !isset( $this->dbConn ) ) {
- $class = 'Database' . ucfirst( $this->dbType );
+ $class = DatabaseBase::classFromType( $this->dbType );
$this->dbConn = new $class( $this->dbServer, $this->dbUser,
$this->dbPassword, $this->dbName, $this->dbFlags,
$this->tablePrefix );
$dbSupport = '';
foreach( $this->parent->getDBTypes() as $type ) {
- $db = 'Database' . ucfirst( $type );
+ $db = DatabaseBase::classFromType( $type );
$dbSupport .= wfMsgNoTrans( "config-support-$type",
call_user_func( array( $db, 'getSoftwareLink' ) ) ) . "\n";
}