本文整理汇总了PHP中IDatabase类的典型用法代码示例。如果您正苦于以下问题:PHP IDatabase类的具体用法?PHP IDatabase怎么用?PHP IDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initConnection
protected function initConnection($lockDb, IDatabase $db)
{
# Let this transaction see lock rows from other transactions
$db->query("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
# Do everything in a transaction as it all gets rolled back eventually
$db->startAtomic(__CLASS__);
}
示例2: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$ids = array_map('intval', $this->ids);
$live = $db->select(array('revision', 'page', 'user'), array_merge(Revision::selectFields(), Revision::selectUserFields()), array('rev_page' => $this->title->getArticleID(), 'rev_id' => $ids), __METHOD__, array('ORDER BY' => 'rev_id DESC'), array('page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()));
if ($live->numRows() >= count($ids)) {
// All requested revisions are live, keeps things simple!
return $live;
}
// Check if any requested revisions are available fully deleted.
$archived = $db->select(array('archive'), Revision::selectArchiveFields(), array('ar_rev_id' => $ids), __METHOD__, array('ORDER BY' => 'ar_rev_id DESC'));
if ($archived->numRows() == 0) {
return $live;
} elseif ($live->numRows() == 0) {
return $archived;
} else {
// Combine the two! Whee
$rows = array();
foreach ($live as $row) {
$rows[$row->rev_id] = $row;
}
foreach ($archived as $row) {
$rows[$row->ar_rev_id] = $row;
}
krsort($rows);
return new FakeResultWrapper(array_values($rows));
}
}
示例3: getWeightScale
protected function getWeightScale($index, IDatabase $conn = null)
{
if (!$conn) {
return 0.0;
}
$weight = 1.0;
if ($this->warmCacheRatio > 0) {
$res = $conn->query('SHOW STATUS', false);
$s = $res ? $conn->fetchObject($res) : false;
if ($s === false) {
$host = $this->parent->getServerName($index);
$this->replLogger->error(__METHOD__ . ": could not get status for {$host}");
} else {
// http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html
if ($s->Innodb_buffer_pool_pages_total > 0) {
$ratio = $s->Innodb_buffer_pool_pages_data / $s->Innodb_buffer_pool_pages_total;
} elseif ($s->Qcache_total_blocks > 0) {
$ratio = 1.0 - $s->Qcache_free_blocks / $s->Qcache_total_blocks;
} else {
$ratio = 1.0;
}
// Stop caring once $ratio >= $this->warmCacheRatio
$weight *= min($ratio / $this->warmCacheRatio, 1.0);
}
}
return $weight;
}
示例4: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$ids = array_map('intval', $this->ids);
$queryInfo = ['tables' => ['revision', 'user'], 'fields' => array_merge(Revision::selectFields(), Revision::selectUserFields()), 'conds' => ['rev_page' => $this->title->getArticleID(), 'rev_id' => $ids], 'options' => ['ORDER BY' => 'rev_id DESC'], 'join_conds' => ['page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()]];
ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], '');
$live = $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']);
if ($live->numRows() >= count($ids)) {
// All requested revisions are live, keeps things simple!
return $live;
}
$archiveQueryInfo = ['tables' => ['archive'], 'fields' => Revision::selectArchiveFields(), 'conds' => ['ar_rev_id' => $ids], 'options' => ['ORDER BY' => 'ar_rev_id DESC'], 'join_conds' => []];
ChangeTags::modifyDisplayQuery($archiveQueryInfo['tables'], $archiveQueryInfo['fields'], $archiveQueryInfo['conds'], $archiveQueryInfo['join_conds'], $archiveQueryInfo['options'], '');
// Check if any requested revisions are available fully deleted.
$archived = $db->select($archiveQueryInfo['tables'], $archiveQueryInfo['fields'], $archiveQueryInfo['conds'], __METHOD__, $archiveQueryInfo['options'], $archiveQueryInfo['join_conds']);
if ($archived->numRows() == 0) {
return $live;
} elseif ($live->numRows() == 0) {
return $archived;
} else {
// Combine the two! Whee
$rows = [];
foreach ($live as $row) {
$rows[$row->rev_id] = $row;
}
foreach ($archived as $row) {
$rows[$row->ar_rev_id] = $row;
}
krsort($rows);
return new FakeResultWrapper(array_values($rows));
}
}
示例5: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$ids = array_map('intval', $this->ids);
$queryInfo = array('tables' => array('revision', 'user'), 'fields' => array_merge(Revision::selectFields(), Revision::selectUserFields()), 'conds' => array('rev_page' => $this->title->getArticleID(), 'rev_id' => $ids), 'options' => array('ORDER BY' => 'rev_id DESC'), 'join_conds' => array('page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()));
ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], '');
return $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']);
}
示例6: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$archiveNames = array();
foreach ($this->ids as $timestamp) {
$archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
}
return $db->select('oldimage', OldLocalFile::selectFields(), array('oi_name' => $this->title->getDBkey(), 'oi_archive_name' => $archiveNames), __METHOD__, array('ORDER BY' => 'oi_timestamp DESC'));
}
示例7: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$timestamps = array();
foreach ($this->ids as $id) {
$timestamps[] = $db->timestamp($id);
}
return $db->select('archive', Revision::selectArchiveFields(), array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), 'ar_timestamp' => $timestamps), __METHOD__, array('ORDER BY' => 'ar_timestamp DESC'));
}
示例8: __construct
/**
* @param callable $callback
* @param string $fname Calling method
* @param IDatabase|null $dbw Abort if this DB is rolled back [optional] (since 1.28)
*/
public function __construct(callable $callback, $fname = 'unknown', IDatabase $dbw = null)
{
$this->callback = $callback;
$this->fname = $fname;
if ($dbw && $dbw->trxLevel()) {
$dbw->onTransactionResolution([$this, 'cancelOnRollback'], $fname);
}
}
示例9: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$ids = array_map('intval', $this->ids);
$queryInfo = DatabaseLogEntry::getSelectQueryData();
$queryInfo['conds'] += array('log_id' => $ids);
$queryInfo['options'] += array('ORDER BY' => 'log_id DESC');
ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], '');
return $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']);
}
示例10: __construct
/**
* @param array $params An associative array with one member:
* - connection: An IDatabase connection object
*/
public function __construct(array $params)
{
if (!isset($params['connection'])) {
throw new InvalidArgumentException("Missing 'connection' argument.");
}
$this->db = $params['connection'];
parent::__construct(['servers' => [['type' => $this->db->getType(), 'host' => $this->db->getServer(), 'dbname' => $this->db->getDBname(), 'load' => 1]], 'trxProfiler' => isset($params['trxProfiler']) ? $params['trxProfiler'] : null, 'srvCache' => isset($params['srvCache']) ? $params['srvCache'] : null, 'wanCache' => isset($params['wanCache']) ? $params['wanCache'] : null]);
if (isset($params['readOnlyReason'])) {
$this->db->setLBInfo('readOnlyReason', $params['readOnlyReason']);
}
}
示例11: __construct
/**
* @param IDatabase $db
* @param string $error
* @param int|string $errno
* @param string $sql
* @param string $fname
*/
function __construct(IDatabase $db, $error, $errno, $sql, $fname)
{
if ($db instanceof Database && $db->wasConnectionError($errno)) {
$message = "A connection error occured. \n" . "Query: {$sql}\n" . "Function: {$fname}\n" . "Error: {$errno} {$error}\n";
} else {
$message = "A database query error has occurred. Did you forget to run " . "your application's database schema updater after upgrading? \n" . "Query: {$sql}\n" . "Function: {$fname}\n" . "Error: {$errno} {$error}\n";
}
parent::__construct($db, $message);
$this->error = $error;
$this->errno = $errno;
$this->sql = $sql;
$this->fname = $fname;
}
示例12: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$timestamps = [];
foreach ($this->ids as $id) {
$timestamps[] = $db->timestamp($id);
}
$tables = ['archive'];
$fields = Revision::selectArchiveFields();
$conds = ['ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), 'ar_timestamp' => $timestamps];
$join_conds = [];
$options = ['ORDER BY' => 'ar_timestamp DESC'];
ChangeTags::modifyDisplayQuery($tables, $fields, $conds, $join_conds, $options, '');
return $db->select($tables, $fields, $conds, __METHOD__, $options, $join_conds);
}
示例13: getSearchEngineClass
/**
* @param IDatabase $db
* @return string SearchEngine subclass name
* @since 1.28
*/
public static function getSearchEngineClass(IDatabase $db)
{
switch ($db->getType()) {
case 'sqlite':
return 'SearchSqlite';
case 'mysql':
return 'SearchMySQL';
case 'postgres':
return 'SearchPostgres';
case 'mssql':
return 'SearchMssql';
case 'oracle':
return 'SearchOracle';
default:
return 'SearchEngineDummy';
}
}
示例14: write
/**
* @param array $updates Array of arrays each containing two keys, 'primaryKey'
* and 'changes'. primaryKey must contain a map of column names to values
* sufficient to uniquely identify the row changes must contain a map of column
* names to update values to apply to the row.
*/
public function write(array $updates)
{
$this->db->begin();
foreach ($updates as $update) {
$this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
}
$this->db->commit();
wfWaitForSlaves(false, false, $this->clusterName);
}
示例15: write
/**
* @param array $updates Array of arrays each containing two keys, 'primaryKey'
* and 'changes'. primaryKey must contain a map of column names to values
* sufficient to uniquely identify the row changes must contain a map of column
* names to update values to apply to the row.
*/
public function write(array $updates)
{
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
foreach ($updates as $update) {
$this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
}
$lbFactory->commitAndWaitForReplication(__METHOD__, $ticket);
}