本文整理汇总了PHP中DatabaseBase::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase::factory方法的具体用法?PHP DatabaseBase::factory怎么用?PHP DatabaseBase::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseBase
的用法示例。
在下文中一共展示了DatabaseBase::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMasterDB
/**
* @return DatabaseBase
*/
function getMasterDB()
{
if (!isset($this->dbConn)) {
$this->dbConn = DatabaseBase::factory($this->dbType, array('host' => $this->dbServer, 'user' => $this->dbUser, 'password' => $this->dbPassword, 'dbname' => $this->dbName, 'flags' => $this->dbFlags, 'tablePrefix' => $this->tablePrefix));
}
return $this->dbConn;
}
示例2: getDB
/**
* Get the Query database connection (read-only)
* @return DatabaseBase
*/
protected function getDB()
{
if (is_null($this->mDb)) {
global $wgMetricsDBserver, $wgMetricsDBname, $wgMetricsDBuser, $wgMetricsDBpassword, $wgMetricsDBtype, $wgMetricsDBprefix, $wgDebugDumpSql;
$this->mDb = DatabaseBase::factory($wgMetricsDBtype, array('host' => $wgMetricsDBserver, 'user' => $wgMetricsDBuser, 'password' => $wgMetricsDBpassword, 'dbname' => $wgMetricsDBname, 'tablePrefix' => $wgMetricsDBprefix, 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT));
//$this->mDb->query( "SET names utf8" );
}
return $this->mDb;
}
示例3: getDB
/**
* @return DatabaseBase
*/
protected function getDB()
{
if (is_null($this->db)) {
global $wgMetricsDBserver, $wgMetricsDBname, $wgMetricsDBuser, $wgMetricsDBpassword, $wgMetricsDBtype, $wgMetricsDBprefix;
$this->db = DatabaseBase::factory($wgMetricsDBtype, array('host' => $wgMetricsDBserver, 'user' => $wgMetricsDBuser, 'password' => $wgMetricsDBpassword, 'dbname' => $wgMetricsDBname, 'tablePrefix' => $wgMetricsDBprefix));
//$this->db->query( "SET names utf8" );
}
return $this->db;
}
示例4: __construct
function __construct()
{
$this->dbr = wfGetDB(DB_SLAVE);
$this->dbw = DatabaseBase::factory('mysql');
$this->dbw->open(WH_DATABASE_BACKUP, WH_DATABASE_MAINTENANCE_USER, WH_DATABASE_MAINTENANCE_PASSWORD, self::STU_DATABASE);
$this->pagesProcessed = 0;
$this->errors = false;
$this->warnings = false;
$this->dryRun = false;
}
示例5: getDBR
private function getDBR()
{
global $wgDBname;
if (strpos(@$_SERVER['HOSTNAME'], 'wikidiy.com') !== false) {
define(WAP_DB_HOST, WH_DATABASE_MASTER);
} else {
define(WAP_DB_HOST, WH_DATABASE_BACKUP);
}
$db = DatabaseBase::factory('mysql');
$db->open(WAP_DB_HOST, WH_DATABASE_MAINTENANCE_USER, WH_DATABASE_MAINTENANCE_PASSWORD, $wgDBname);
return $db;
}
示例6: updateRemote
function updateRemote()
{
global $wgUser, $wgVanillaDB;
try {
$db = DatabaseBase::factory('mysql');
$db->open($wgVanillaDB['host'], $wgVanillaDB['user'], $wgVanillaDB['password'], $wgVanillaDB['dbname']);
$oldignore = $db->ignoreErrors(true);
// get vanilla user id
$vid = $db->selectField('GDN_UserAuthentication', array('UserID'), array('ForeignUserKey' => $wgUser->getID()));
if (!$vid) {
return true;
}
$photo = Avatar::getAvatarURL($wgUser->getName());
$updates = array("Photo" => $photo, "Email" => $wgUser->getEmail());
if (in_array('bureaucrat', $wgUser->getGroups())) {
$updates["Admin"] = 1;
} else {
$updates["Admin"] = 0;
}
$opts = array('UserID' => $vid);
$db->update('GDN_User', $updates, $opts);
if (self::isUserBlocked()) {
$db->update('GDN_UserRole', array('RoleID = 1'), $opts);
} else {
if (in_array('bureaucrat', $wgUser->getGroups())) {
$db->update('GDN_UserRole', array('RoleID = 16'), $opts);
} else {
if (in_array('sysop', $wgUser->getGroups())) {
$db->update("GDN_User", array('Permissions' => 'a:14:{i:0;s:19:"Garden.SignIn.Allow";i:1;s:22:"Garden.Activity.Delete";i:2;s:25:"Vanilla.Categories.Manage";i:3;s:19:"Vanilla.Spam.Manage";s:24:"Vanilla.Discussions.View";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:23:"Vanilla.Discussions.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:24:"Vanilla.Discussions.Edit";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:28:"Vanilla.Discussions.Announce";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:24:"Vanilla.Discussions.Sink";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:25:"Vanilla.Discussions.Close";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:26:"Vanilla.Discussions.Delete";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:20:"Vanilla.Comments.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:21:"Vanilla.Comments.Edit";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:23:"Vanilla.Comments.Delete";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}}'), $opts);
$db->update('GDN_UserRole', array('RoleID = 32'), $opts);
} else {
$db->update("GDN_User", array('Permissions' => 'a:4:{i:0;s:19:"Garden.SignIn.Allow";s:24:"Vanilla.Discussions.View";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:23:"Vanilla.Discussions.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:20:"Vanilla.Comments.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}}'), $opts);
$db->update('GDN_UserRole', array('RoleID = 8'), $opts);
print $db->lastQuery();
}
}
}
$db->ignoreErrors($oldignore);
} catch (Exception $e) {
print "oops {$e->getMessage()}\n";
}
return true;
}
示例7: setAvatar
public static function setAvatar($user)
{
global $wgVanillaDB;
$fname = "Vanilla::setAvatar";
wfProfileIn($fname);
$db = DatabaseBase::factory('mysql');
$db->open($wgVanillaDB['host'], $wgVanillaDB['user'], $wgVanillaDB['password'], $wgVanillaDB['dbname']);
// get vanilla user id
$vid = $db->selectField('GDN_UserAuthentication', array('UserID'), array('ForeignUserKey' => $user->getID()));
if (!$vid) {
return false;
}
$updates = array("Photo" => Avatar::getAvatarURL($user->getName()));
$opts = array('UserID' => $vid);
$db->update('GDN_User', $updates, $opts);
wfDebug("Vanilla: Updating avatar " . print_r($updates, true) . print_r($opts, true) . "\n");
wfProfileOut($fname);
return true;
}
示例8: getDB
/**
* Get a connection to the specified database
*
* @param int $serverIndex
* @return DatabaseBase
* @throws MWException
*/
protected function getDB($serverIndex)
{
global $wgDebugDBTransactions;
if (!isset($this->conns[$serverIndex])) {
if ($serverIndex >= $this->numServers) {
throw new MWException(__METHOD__ . ": Invalid server index \"{$serverIndex}\"");
}
# Don't keep timing out trying to connect for each call if the DB is down
if (isset($this->connFailureErrors[$serverIndex]) && time() - $this->connFailureTimes[$serverIndex] < 60) {
throw $this->connFailureErrors[$serverIndex];
}
# If server connection info was given, use that
if ($this->serverInfos) {
if ($wgDebugDBTransactions) {
$this->logger->debug("Using provided serverInfo for SqlBagOStuff");
}
$info = $this->serverInfos[$serverIndex];
$type = isset($info['type']) ? $info['type'] : 'mysql';
$host = isset($info['host']) ? $info['host'] : '[unknown]';
$this->logger->debug(__CLASS__ . ": connecting to {$host}");
// Use a blank trx profiler to ignore expections as this is a cache
$info['trxProfiler'] = new TransactionProfiler();
$db = DatabaseBase::factory($type, $info);
$db->clearFlag(DBO_TRX);
} else {
/*
* We must keep a separate connection to MySQL in order to avoid deadlocks
* However, SQLite has an opposite behavior. And PostgreSQL needs to know
* if we are in transaction or no
*/
$index = $this->slaveOnly ? DB_SLAVE : DB_MASTER;
if (wfGetDB($index)->getType() == 'mysql') {
$this->lb = wfGetLBFactory()->newMainLB();
$db = $this->lb->getConnection($index);
$db->clearFlag(DBO_TRX);
// auto-commit mode
} else {
$db = wfGetDB($index);
}
}
if ($wgDebugDBTransactions) {
$this->logger->debug(sprintf("Connection %s will be used for SqlBagOStuff", $db));
}
$this->conns[$serverIndex] = $db;
}
return $this->conns[$serverIndex];
}
示例9: openConnectionWithParams
/**
* Open a PG connection with given parameters
* @param string $user User name
* @param string $password Password
* @param string $dbName Database name
* @param string $schema Database schema
* @return Status
*/
protected function openConnectionWithParams($user, $password, $dbName, $schema)
{
$status = Status::newGood();
try {
$db = DatabaseBase::factory('postgres', array('host' => $this->getVar('wgDBserver'), 'user' => $user, 'password' => $password, 'dbname' => $dbName, 'schema' => $schema));
$status->value = $db;
} catch (DBConnectionError $e) {
$status->fatal('config-connection-error', $e->getMessage());
}
return $status;
}
示例10: setupDatabase
/**
* @return Status
*/
public function setupDatabase()
{
$dir = $this->getVar('wgSQLiteDataDir');
# Sanity check. We checked this before but maybe someone deleted the
# data dir between then and now
$dir_status = self::dataDirOKmaybeCreate($dir, false);
if (!$dir_status->isOK()) {
return $dir_status;
}
$db = $this->getVar('wgDBname');
# Make the main and cache stub DB files
$status = Status::newGood();
$status->merge($this->makeStubDBFile($dir, $db));
$status->merge($this->makeStubDBFile($dir, "wikicache"));
if (!$status->isOK()) {
return $status;
}
# Nuke the unused settings for clarity
$this->setVar('wgDBserver', '');
$this->setVar('wgDBuser', '');
$this->setVar('wgDBpassword', '');
$this->setupSchemaVars();
# Create the global cache DB
try {
global $wgSQLiteDataDir;
# @todo FIXME: setting globals kind of sucks
$wgSQLiteDataDir = $dir;
$conn = DatabaseBase::factory('sqlite', array('dbname' => "wikicache"));
# @todo: don't duplicate objectcache definition, though it's very simple
$sql = <<<EOT
\tCREATE TABLE IF NOT EXISTS objectcache (
\t keyname BLOB NOT NULL default '' PRIMARY KEY,
\t value BLOB,
\t exptime TEXT
\t)
EOT;
$conn->query($sql);
$conn->query("CREATE INDEX IF NOT EXISTS exptime ON objectcache (exptime)");
$conn->query("PRAGMA journal_mode=WAL");
// this is permanent
$conn->close();
} catch (DBConnectionError $e) {
return Status::newFatal('config-sqlite-connection-error', $e->getMessage());
}
# Open the main DB
return $this->getConnection();
}
示例11: reallyOpenConnection
/**
* Really opens a connection. Uncached.
* Returns a Database object whether or not the connection was successful.
* @access private
*
* @param array $server
* @param bool $dbNameOverride
* @throws MWException
* @return DatabaseBase
*/
protected function reallyOpenConnection($server, $dbNameOverride = false)
{
if (!is_array($server)) {
throw new MWException('You must update your load-balancing configuration. ' . 'See DefaultSettings.php entry for $wgDBservers.');
}
if ($dbNameOverride !== false) {
$server['dbname'] = $dbNameOverride;
}
// Log when many connection are made on requests
if (++$this->connsOpened >= self::CONN_HELD_WARN_THRESHOLD) {
$masterAddr = $this->getServerName(0);
wfDebugLog('DBPerformance', __METHOD__ . ": " . "{$this->connsOpened}+ connections made (master={$masterAddr})\n" . wfBacktrace(true));
}
# Create object
try {
$db = DatabaseBase::factory($server['type'], $server);
} catch (DBConnectionError $e) {
// FIXME: This is probably the ugliest thing I have ever done to
// PHP. I'm half-expecting it to segfault, just out of disgust. -- TS
$db = $e->db;
}
$db->setLBInfo($server);
if (isset($server['fakeSlaveLag'])) {
$db->setFakeSlaveLag($server['fakeSlaveLag']);
}
if (isset($server['fakeMaster'])) {
$db->setFakeMaster(true);
}
return $db;
}
示例12: getConnection
/**
* Get (or reuse) a connection to a lock DB
*
* @param string $lockDb
* @return IDatabase
* @throws DBError
*/
protected function getConnection($lockDb)
{
if (!isset($this->conns[$lockDb])) {
$db = null;
if ($lockDb === 'localDBMaster') {
$lb = wfGetLBFactory()->getMainLB($this->domain);
$db = $lb->getConnection(DB_MASTER, array(), $this->domain);
} elseif (isset($this->dbServers[$lockDb])) {
$config = $this->dbServers[$lockDb];
$db = DatabaseBase::factory($config['type'], $config);
}
if (!$db) {
return null;
// config error?
}
$this->conns[$lockDb] = $db;
$this->conns[$lockDb]->clearFlag(DBO_TRX);
# If the connection drops, try to avoid letting the DB rollback
# and release the locks before the file operations are finished.
# This won't handle the case of DB server restarts however.
$options = array();
if ($this->lockExpiry > 0) {
$options['connTimeout'] = $this->lockExpiry;
}
$this->conns[$lockDb]->setSessionOptions($options);
$this->initConnection($lockDb, $this->conns[$lockDb]);
}
if (!$this->conns[$lockDb]->trxLevel()) {
$this->conns[$lockDb]->begin(__METHOD__);
// start transaction
}
return $this->conns[$lockDb];
}
示例13: openConnectionToAnyDB
public function openConnectionToAnyDB($user, $password)
{
$dbs = array('template1', 'postgres');
if (!in_array($this->getVar('wgDBname'), $dbs)) {
array_unshift($dbs, $this->getVar('wgDBname'));
}
$conn = false;
$status = Status::newGood();
foreach ($dbs as $db) {
try {
$p = array('host' => $this->getVar('wgDBserver'), 'user' => $user, 'password' => $password, 'dbname' => $db);
$conn = DatabaseBase::factory('postgres', $p);
} catch (DBConnectionError $error) {
$conn = false;
$status->fatal('config-pg-test-error', $db, $error->getMessage());
}
if ($conn !== false) {
break;
}
}
if ($conn !== false) {
return Status::newGood($conn);
} else {
return $status;
}
}
示例14: newStandaloneInstance
/**
* @param string $filename
* @param array $p Options map; supports:
* - flags : (same as __construct counterpart)
* - trxMode : (same as __construct counterpart)
* - dbDirectory : (same as __construct counterpart)
* @return DatabaseSqlite
* @since 1.25
*/
public static function newStandaloneInstance($filename, array $p = array())
{
$p['dbFilePath'] = $filename;
$p['schema'] = false;
$p['tablePrefix'] = '';
return DatabaseBase::factory('sqlite', $p);
}
示例15: reallyOpenConnection
/**
* Really opens a connection. Uncached.
* Returns a Database object whether or not the connection was successful.
* @access private
*
* @return DatabaseBase
*/
function reallyOpenConnection($server, $dbNameOverride = false)
{
if (!is_array($server)) {
throw new MWException('You must update your load-balancing configuration. ' . 'See DefaultSettings.php entry for $wgDBservers.');
}
$host = $server['host'];
$dbname = $server['dbname'];
if ($dbNameOverride !== false) {
$server['dbname'] = $dbname = $dbNameOverride;
}
# Create object
wfDebug("Connecting to {$host} {$dbname}...\n");
try {
$db = DatabaseBase::factory($server['type'], $server);
} catch (DBConnectionError $e) {
// FIXME: This is probably the ugliest thing I have ever done to
// PHP. I'm half-expecting it to segfault, just out of disgust. -- TS
$db = $e->db;
}
if ($db->isOpen()) {
wfDebug("Connected to {$host} {$dbname}.\n");
} else {
wfDebug("Connection failed to {$host} {$dbname}.\n");
}
$db->setLBInfo($server);
if (isset($server['fakeSlaveLag'])) {
$db->setFakeSlaveLag($server['fakeSlaveLag']);
}
if (isset($server['fakeMaster'])) {
$db->setFakeMaster(true);
}
return $db;
}