本文整理汇总了PHP中IDatabase类的典型用法代码示例。如果您正苦于以下问题:PHP IDatabase类的具体用法?PHP IDatabase怎么用?PHP IDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IDatabase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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__);
}
开发者ID:paladox,项目名称:mediawiki,代码行数:7,代码来源:MySqlLockManager.php
示例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));
}
}
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:31,代码来源:RevDelRevisionList.php
示例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;
}
开发者ID:paladox,项目名称:mediawiki,代码行数:27,代码来源:LoadMonitorMySQL.php
示例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));
}
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:35,代码来源:RevDelRevisionList.php
示例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']);
}
开发者ID:mb720,项目名称:mediawiki,代码行数:11,代码来源:ChangeTagsRevisionList.php
示例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'));
}
开发者ID:xfstudio,项目名称:mediawiki,代码行数:12,代码来源:RevDelFileList.php
示例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'));
}
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:12,代码来源:RevDelArchiveList.php
示例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);
}
}
开发者ID:paladox,项目名称:mediawiki,代码行数:13,代码来源:MWCallableUpdate.php
示例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']);
}
开发者ID:mb720,项目名称:mediawiki,代码行数:13,代码来源:ChangeTagsLogList.php
示例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']);
}
}
开发者ID:paladox,项目名称:mediawiki,代码行数:15,代码来源:LoadBalancerSingle.php
示例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;
}
开发者ID:paladox,项目名称:mediawiki,代码行数:20,代码来源:DBQueryError.php
示例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);
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:18,代码来源:RevDelArchiveList.php
示例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';
}
}
开发者ID:paladox,项目名称:mediawiki,代码行数:22,代码来源:SearchEngineFactory.php
示例14: getMasterDB
/**
* Get a master connection to the logging DB
*
* @return IDatabase
* @throws DBError
*/
protected function getMasterDB()
{
if (!$this->dbw) {
// Get a separate connection in autocommit mode
$lb = wfGetLBFactory()->newMainLB();
$this->dbw = $lb->getConnection(DB_MASTER, array(), $this->wiki);
$this->dbw->clearFlag(DBO_TRX);
}
return $this->dbw;
}
开发者ID:Acidburn0zzz,项目名称:mediawiki,代码行数:16,代码来源:DBFileJournal.php
示例15: count
/**
* @param IDatabase $db
* @param resource $stmt A valid OCI statement identifier
* @param bool $unique
*/
function __construct(&$db, $stmt, $unique = false)
{
$this->db =& $db;
$this->nrows = oci_fetch_all($stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM);
if ($this->nrows === false) {
$e = oci_error($stmt);
$db->reportQueryError($e['message'], $e['code'], '', __METHOD__);
$this->free();
return;
}
if ($unique) {
$this->rows = $this->array_unique_md($this->rows);
$this->nrows = count($this->rows);
}
if ($this->nrows > 0) {
foreach ($this->rows[0] as $k => $v) {
$this->columns[$k] = strtolower(oci_field_name($stmt, $k + 1));
}
}
$this->cursor = 0;
oci_free_statement($stmt);
}
开发者ID:paladox,项目名称:mediawiki,代码行数:27,代码来源:DatabaseOracle.php
示例16: invalidatePages
/**
* Invalidate the cache of a list of pages from a single namespace.
* This is intended for use by subclasses.
*
* @param IDatabase $dbw
* @param int $namespace Namespace number
* @param array $dbkeys
*/
public static function invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
{
if ($dbkeys === []) {
return;
}
$dbw->onTransactionIdle(function () use($dbw, $namespace, $dbkeys) {
$services = MediaWikiServices::getInstance();
$lbFactory = $services->getDBLoadBalancerFactory();
// Determine which pages need to be updated.
// This is necessary to prevent the job queue from smashing the DB with
// large numbers of concurrent invalidations of the same page.
$now = $dbw->timestamp();
$ids = $dbw->selectFieldValues('page', 'page_id', ['page_namespace' => $namespace, 'page_title' => $dbkeys, 'page_touched < ' . $dbw->addQuotes($now)], __METHOD__);
if (!$ids) {
return;
}
$batchSize = $services->getMainConfig()->get('UpdateRowsPerQuery');
$ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
foreach (array_chunk($ids, $batchSize) as $idBatch) {
$dbw->update('page', ['page_touched' => $now], ['page_id' => $idBatch, 'page_touched < ' . $dbw->addQuotes($now)], __METHOD__);
$lbFactory->commitAndWaitForReplication(__METHOD__, $ticket);
}
}, __METHOD__);
}
开发者ID:paladox,项目名称:mediawiki,代码行数:32,代码来源:PurgeJobUtils.php
示例17: countItems
/**
* Count the number of items on a user's watchlist
*
* @param IDatabase $dbr A database connection
* @return int
*/
protected function countItems($dbr)
{
# Fetch the raw count
$rows = $dbr->select('watchlist', array('count' => 'COUNT(*)'), array('wl_user' => $this->getUser()->getId()), __METHOD__);
$row = $dbr->fetchObject($rows);
$count = $row->count;
return floor($count / 2);
}
开发者ID:admonkey,项目名称:mediawiki,代码行数:14,代码来源:SpecialWatchlist.php
示例18: listPages
/**
* @param IDatabase $dbr
* @param string|array $condition
* @return bool|ResultWrapper
*/
protected static function listPages($dbr, $condition)
{
return $dbr->select(array('archive'), array('ar_namespace', 'ar_title', 'count' => 'COUNT(*)'), $condition, __METHOD__, array('GROUP BY' => array('ar_namespace', 'ar_title'), 'ORDER BY' => array('ar_namespace', 'ar_title'), 'LIMIT' => 100));
}
开发者ID:raymondzhangl,项目名称:mediawiki,代码行数:9,代码来源:SpecialUndelete.php
示例19: doQuery
/**
* @param IDatabase $db
* @return mixed
*/
public function doQuery($db)
{
$conds = ['rev_page' => $this->title->getArticleID()];
if ($this->ids !== null) {
$conds['rev_id'] = array_map('intval', $this->ids);
}
return $db->select(['revision', 'page', 'user'], array_merge(Revision::selectFields(), Revision::selectUserFields()), $conds, __METHOD__, ['ORDER BY' => 'rev_id DESC'], ['page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()]);
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:12,代码来源:RevisionList.php
示例20: updateIfNewerOn
/**
* If the given revision is newer than the currently set page_latest,
* update the page record. Otherwise, do nothing.
*
* @deprecated since 1.24, use updateRevisionOn instead
*
* @param IDatabase $dbw
* @param Revision $revision
* @return bool
*/
public function updateIfNewerOn($dbw, $revision)
{
$row = $dbw->selectRow(['revision', 'page'], ['rev_id', 'rev_timestamp', 'page_is_redirect'], ['page_id' => $this->getId(), 'page_latest=rev_id'], __METHOD__);
if ($row) {
if (wfTimestamp(TS_MW, $row->rev_timestamp) >= $revision->getTimestamp()) {
return false;
}
$prev = $row->rev_id;
$lastRevIsRedirect = (bool) $row->page_is_redirect;
} else {
// No or missing previous revision; mark the page as new
$prev = 0;
$lastRevIsRedirect = null;
}
$ret = $this->updateRevisionOn($dbw, $revision, $prev, $lastRevIsRedirect);
return $ret;
}
开发者ID:paladox,项目名称:mediawiki,代码行数:27,代码来源:WikiPage.php
注:本文中的IDatabase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论