本文整理汇总了PHP中DatabaseBase::select方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase::select方法的具体用法?PHP DatabaseBase::select怎么用?PHP DatabaseBase::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseBase
的用法示例。
在下文中一共展示了DatabaseBase::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateSearchIndex
/**
* Populates the search index with content from all pages
*/
protected function populateSearchIndex()
{
$res = $this->db->select('page', 'MAX(page_id) AS count');
$s = $this->db->fetchObject($res);
$count = $s->count;
$this->output("Rebuilding index fields for {$count} pages...\n");
$n = 0;
$fields = array_merge(Revision::selectPageFields(), Revision::selectFields(), Revision::selectTextFields());
while ($n < $count) {
if ($n) {
$this->output($n . "\n");
}
$end = $n + self::RTI_CHUNK_SIZE - 1;
$res = $this->db->select(['page', 'revision', 'text'], $fields, ["page_id BETWEEN {$n} AND {$end}", 'page_latest = rev_id', 'rev_text_id = old_id'], __METHOD__);
foreach ($res as $s) {
try {
$title = Title::makeTitle($s->page_namespace, $s->page_title);
$rev = new Revision($s);
$content = $rev->getContent();
$u = new SearchUpdate($s->page_id, $title, $content);
$u->doUpdate();
} catch (MWContentSerializationException $ex) {
$this->output("Failed to deserialize content of revision {$s->rev_id} of page " . "`" . $title->getPrefixedDBkey() . "`!\n");
}
}
$n += self::RTI_CHUNK_SIZE;
}
}
示例2: 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));
}
}
示例3: getLinksFromPage
/**
* Get all global images from a certain page
*/
public function getLinksFromPage($id)
{
$res = $this->db->select('globalimagelinks', 'gil_to', array('gil_wiki' => $this->interwiki, 'gil_page' => $id), __METHOD__);
$images = array();
foreach ($res as $row) {
$images[] = $row->gil_to;
}
return $images;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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']);
}
示例7: copyExactMatch
function copyExactMatch($srcTable, $dstTable, $copyPos)
{
$numRowsCopied = 0;
$srcRes = $this->dbw->select($srcTable, '*', array('log_timestamp' => $copyPos), __METHOD__);
$dstRes = $this->dbw->select($dstTable, '*', array('log_timestamp' => $copyPos), __METHOD__);
if ($srcRes->numRows()) {
$srcRow = $srcRes->fetchObject();
$srcFields = array_keys((array) $srcRow);
$srcRes->seek(0);
$dstRowsSeen = array();
# Make a hashtable of rows that already exist in the destination
foreach ($dstRes as $dstRow) {
$reducedDstRow = array();
foreach ($srcFields as $field) {
$reducedDstRow[$field] = $dstRow->{$field};
}
$hash = md5(serialize($reducedDstRow));
$dstRowsSeen[$hash] = true;
}
# Copy all the source rows that aren't already in the destination
foreach ($srcRes as $srcRow) {
$hash = md5(serialize((array) $srcRow));
if (!isset($dstRowsSeen[$hash])) {
$this->dbw->insert($dstTable, (array) $srcRow, __METHOD__);
$numRowsCopied++;
}
}
}
return $numRowsCopied;
}
示例8: 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'));
}
示例9: 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'));
}
示例10: 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']);
}
示例11: getTargetList
/**
* Find pages in main and talk namespaces that have a prefix of the new
* namespace so we know titles that will need migrating
*
* @param int $ns Destination namespace id
* @param string $name Prefix that is being made a namespace
* @param array $options Associative array of validated command-line options
*
* @return ResultWrapper
*/
private function getTargetList($ns, $name, $options)
{
if ($options['move-talk'] && MWNamespace::isSubject($ns)) {
$checkNamespaces = array(NS_MAIN, NS_TALK);
} else {
$checkNamespaces = NS_MAIN;
}
return $this->db->select('page', array('page_id', 'page_title', 'page_namespace'), array('page_namespace' => $checkNamespaces, 'page_title' . $this->db->buildLike("{$name}:", $this->db->anyString())), __METHOD__);
}
示例12: next
/**
* Fetch the next set of rows from the database.
*/
public function next()
{
$res = $this->db->select($this->table, $this->fetchColumns, $this->buildConditions(), __METHOD__, array('LIMIT' => $this->batchSize, 'ORDER BY' => $this->orderBy), $this->joinConditions);
// The iterator is converted to an array because in addition to
// returning it in self::current() we need to use the end value
// in self::buildConditions()
$this->current = iterator_to_array($res);
$this->key++;
}
示例13: getInterwikiList
/**
* Get the interwiki list
*
* @todo Needs to respect interwiki cache!
* @return Array
*/
private function getInterwikiList()
{
$result = $this->db->select('interwiki', array('iw_prefix'));
$prefixes = array();
foreach ($result as $row) {
$prefixes[] = $row->iw_prefix;
}
return $prefixes;
}
示例14: getConflicts
/**
* Find pages in mainspace that have a prefix of the new namespace
* so we know titles that will need migrating
*
* @param int $ns Namespace id (id for new namespace?)
* @param string $name Prefix that is being made a namespace
*
* @return array
*/
private function getConflicts($ns, $name)
{
$titleSql = "TRIM(LEADING {$this->db->addQuotes("{$name}:")} FROM page_title)";
if ($ns == 0) {
// An interwiki; try an alternate encoding with '-' for ':'
$titleSql = $this->db->buildConcat(array($this->db->addQuotes("{$name}-"), $titleSql));
}
return iterator_to_array($this->db->select('page', array('id' => 'page_id', 'oldtitle' => 'page_title', 'namespace' => $this->db->addQuotes($ns) . ' + page_namespace', 'title' => $titleSql, 'oldnamespace' => 'page_namespace'), array('page_namespace' => array(0, 1), 'page_title' . $this->db->buildLike("{$name}:", $this->db->anyString())), __METHOD__));
}
示例15: getGroups
/**
* @return array
*/
public function getGroups()
{
# @todo FIXME: Untested.
$groups = array();
$res = $this->mDb->select('user_groups', 'ug_group', array('ug_user' => $this->mRow->user_id), __METHOD__);
foreach ($res as $row) {
$groups[] = $row->ug_group;
}
return $groups;
}