本文整理汇总了PHP中DatabaseBase类的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase类的具体用法?PHP DatabaseBase怎么用?PHP DatabaseBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DatabaseBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteRevs
/**
* Delete one or more revisions from the database
* Do this inside a transaction
*
* @param array $id Array of revision id values
* @param DatabaseBase $dbw DatabaseBase class (needs to be a master)
*/
private function deleteRevs($id, &$dbw)
{
if (!is_array($id)) {
$id = array($id);
}
$dbw->delete('revision', array('rev_id' => $id), __METHOD__);
}
示例2: doQuery
/**
* @param DatabaseBase $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']);
}
示例3: convertOptionBatch
/**
* @param ResultWrapper $res
* @param DatabaseBase $dbw
* @return null|int
*/
function convertOptionBatch($res, $dbw)
{
$id = null;
foreach ($res as $row) {
$this->mConversionCount++;
$insertRows = array();
foreach (explode("\n", $row->user_options) as $s) {
$m = array();
if (!preg_match("/^(.[^=]*)=(.*)\$/", $s, $m)) {
continue;
}
// MW < 1.16 would save even default values. Filter them out
// here (as in User) to avoid adding many unnecessary rows.
$defaultOption = User::getDefaultOption($m[1]);
if (is_null($defaultOption) || $m[2] != $defaultOption) {
$insertRows[] = array('up_user' => $row->user_id, 'up_property' => $m[1], 'up_value' => $m[2]);
}
}
if (count($insertRows)) {
$dbw->insert('user_properties', $insertRows, __METHOD__, array('IGNORE'));
}
$dbw->update('user', array('user_options' => ''), array('user_id' => $row->user_id), __METHOD__);
$id = $row->user_id;
}
return $id;
}
示例4: updateRevision
public function updateRevision($columnPrefix, DatabaseBase $dbw, $continue = null)
{
$rows = $dbw->select('flow_revision', array('rev_id', 'rev_type'), array('rev_id > ' . $dbw->addQuotes($continue), "{$columnPrefix}_id > 0", "{$columnPrefix}_ip IS NOT NULL"), __METHOD__, array('LIMIT' => $this->mBatchSize, 'ORDER BY' => 'rev_id'));
$ids = $objs = array();
foreach ($rows as $row) {
$id = UUID::create($row->rev_id);
$type = self::$types[$row->rev_type];
$om = $this->storage->getStorage($type);
$obj = $om->get($id);
if ($obj) {
$om->merge($obj);
$ids[] = $row->rev_id;
$objs[] = $obj;
} else {
$this->error(__METHOD__ . ": Failed loading {$type}: " . $id->getAlphadecimal());
}
}
if (!$ids) {
return null;
}
$dbw->update('flow_revision', array("{$columnPrefix}_ip" => null), array('rev_id' => $ids), __METHOD__);
foreach ($objs as $obj) {
$this->storage->cachePurge($obj);
}
$this->completeCount += count($ids);
return end($ids);
}
示例5: refreshBatch
public function refreshBatch(DatabaseBase $dbr, UUID $continue, $countableActions, UUID $stop)
{
$rows = $dbr->select('flow_revision', array('rev_id', 'rev_user_id'), array('rev_id > ' . $dbr->addQuotes($continue->getBinary()), 'rev_id <= ' . $dbr->addQuotes($stop->getBinary()), 'rev_user_id > 0', 'rev_user_wiki' => wfWikiID(), 'rev_change_type' => $countableActions), __METHOD__, array('ORDER BY' => 'rev_id ASC', 'LIMIT' => $this->mBatchSize));
// end of data
if (!$rows || $rows->numRows() === 0) {
return false;
}
foreach ($rows as $row) {
// User::incEditCount only allows for edit count to be increased 1
// at a time. It'd be better to immediately be able to increase the
// edit count by the exact number it should be increased with, but
// I'd rather re-use existing code, especially in a run-once script,
// where performance is not the most important thing ;)
$user = User::newFromId($row->rev_user_id);
$user->incEditCount();
// save updates so we can print them when the script is done running
if (!isset($this->updates[$user->getId()])) {
$this->updates[$user->getId()] = 0;
}
$this->updates[$user->getId()]++;
// set value for next batch to continue at
$continue = $row->rev_id;
}
return UUID::create($continue);
}
示例6: getSQLCondition
/**
* @see SMWDescription::getSQLCondition
*
* FIXME: store specific code should be in the store component
*
* @since 0.6
*
* @param string $tableName
* @param array $fieldNames
* @param DatabaseBase $dbs
*
* @return boolean
*/
public function getSQLCondition($tableName, array $fieldNames, DatabaseBase $dbs)
{
$dataItem = $this->getDataItem();
// Only execute the query when the description's type is geographical coordinates,
// the description is valid, and the near comparator is used.
if ($dataItem instanceof SMWDIGeoCoord) {
switch ($this->getComparator()) {
case SMW_CMP_EQ:
$comparator = '=';
break;
case SMW_CMP_LEQ:
$comparator = '<=';
break;
case SMW_CMP_GEQ:
$comparator = '>=';
break;
case SMW_CMP_NEQ:
$comparator = '!=';
break;
default:
return false;
}
$lat = $dbs->addQuotes($dataItem->getLatitude());
$lon = $dbs->addQuotes($dataItem->getLongitude());
$conditions = array();
$conditions[] = "{$tableName}.{$fieldNames['1']} {$comparator} {$lat}";
$conditions[] = "{$tableName}.{$fieldNames['2']} {$comparator} {$lon}";
return implode(' AND ', $conditions);
}
return false;
}
示例7: updateUserWikiCount
function updateUserWikiCount(DatabaseBase $db, $userId, $wikiCount)
{
$res = $db->update("webmaster_user_accounts", array("wikis_number" => $wikiCount), array("user_id" => $userId));
if (!$res) {
throw new Exception("Failed to update User id=" . $userId . " count = " . $wikiCount);
}
}
示例8: doQuery
/**
* @param DatabaseBase $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));
}
}
示例9: lockTables
/**
* Lock the appropriate tables for the script
* @param DatabaseBase $db
* @param string $extraTable The name of any extra tables to lock (eg: text)
*/
private function lockTables($db, $extraTable = [])
{
$tbls = ['page', 'revision', 'redirect'];
if ($extraTable) {
$tbls = array_merge($tbls, $extraTable);
}
$db->lockTables([], $tbls, __METHOD__, false);
}
示例10: doQuery
/**
* @param DatabaseBase $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'));
}
示例11: doQuery
/**
* @param DatabaseBase $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'));
}
示例12: doQuery
/**
* @param DatabaseBase $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']);
}
示例13: doGetText
/**
* May throw a database error if, say, the server dies during query.
* @param DatabaseBase $db
* @param int $id The old_id
* @return string
*/
private function doGetText($db, $id)
{
$id = intval($id);
$row = $db->selectRow('text', ['old_text', 'old_flags'], ['old_id' => $id], __METHOD__);
$text = Revision::getRevisionText($row);
if ($text === false) {
return false;
}
return $text;
}
示例14: buildPostInExpr
public static function buildPostInExpr(\DatabaseBase $db, array $arr)
{
$range = '';
foreach ($arr as $post) {
if ($range) {
$range .= ',';
}
$range .= $db->addQuotes($post->id->getBin());
}
return ' IN(' . $range . ')';
}
示例15: getAccountsToRemove
/**
* Get temp user accounts
*
* - check if these accounts are really temp ones
* - do not remove accounts with password set (122 of them)
*
* @param DatabaseBase $db
* @return int[]
*/
protected function getAccountsToRemove(DatabaseBase $db)
{
$res = $db->select(self::USER_TABLE, ['user_id', 'user_name'], ['user_name ' . $db->buildLike(self::TEMPUSER_PREFIX, $db->anyString()), 'user_password' => ''], __METHOD__);
$users = [];
while ($user = $res->fetchObject()) {
// check if this is really a temp user: "TempUser" + <user ID>
if ($user->user_name === self::TEMPUSER_PREFIX . $user->user_id) {
$users[] = intval($user->user_id);
} else {
$this->output(sprintf(" > skipped %s (#%d)\n", $user->user_name, $user->user_id));
}
}
return $users;
}