本文整理汇总了PHP中DatabaseBase::fetchObject方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase::fetchObject方法的具体用法?PHP DatabaseBase::fetchObject怎么用?PHP DatabaseBase::fetchObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseBase
的用法示例。
在下文中一共展示了DatabaseBase::fetchObject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
while ($n < $count) {
if ($n) {
$this->output($n . "\n");
}
$end = $n + self::RTI_CHUNK_SIZE - 1;
$res = $this->db->select(array('page', 'revision', 'text'), array('page_id', 'page_namespace', 'page_title', 'old_flags', 'old_text'), array("page_id BETWEEN {$n} AND {$end}", 'page_latest = rev_id', 'rev_text_id = old_id'), __METHOD__);
foreach ($res as $s) {
$revtext = Revision::getRevisionText($s);
$u = new SearchUpdate($s->page_id, $s->page_title, $revtext);
$u->doUpdate();
}
$n += self::RTI_CHUNK_SIZE;
}
}
示例3: outputResults
/**
* Format and output report results using the given information plus
* OutputPage
*
* @param OutputPage $out OutputPage to print to
* @param Skin $skin User skin to use [unused]
* @param DatabaseBase $dbr (read) connection to use
* @param int $res Result pointer
* @param int $num Number of available result rows
* @param int $offset Paging offset
*/
protected function outputResults($out, $skin, $dbr, $res, $num, $offset)
{
if ($num > 0) {
$gallery = new ImageGallery();
# $res might contain the whole 1,000 rows, so we read up to
# $num [should update this to use a Pager]
for ($i = 0; $i < $num && ($row = $dbr->fetchObject($res)); $i++) {
$namespace = isset($row->namespace) ? $row->namespace : NS_FILE;
$title = Title::makeTitleSafe($namespace, $row->title);
if ($title instanceof Title && $title->getNamespace() == NS_FILE) {
$gallery->add($title, $this->getCellHtml($row));
}
}
$out->addHTML($gallery->toHtml());
}
}
示例4: fromText
/**
* @param DatabaseBase $db
* @param string $table
* @param string $field
* @return null|PostgresField
*/
static function fromText($db, $table, $field)
{
$q = <<<SQL
SELECT
attnotnull, attlen, conname AS conname,
atthasdef,
adsrc,
COALESCE(condeferred, 'f') AS deferred,
COALESCE(condeferrable, 'f') AS deferrable,
CASE WHEN typname = 'int2' THEN 'smallint'
WHEN typname = 'int4' THEN 'integer'
WHEN typname = 'int8' THEN 'bigint'
WHEN typname = 'bpchar' THEN 'char'
ELSE typname END AS typname
FROM pg_class c
JOIN pg_namespace n ON (n.oid = c.relnamespace)
JOIN pg_attribute a ON (a.attrelid = c.oid)
JOIN pg_type t ON (t.oid = a.atttypid)
LEFT JOIN pg_constraint o ON (o.conrelid = c.oid AND a.attnum = ANY(o.conkey) AND o.contype = 'f')
LEFT JOIN pg_attrdef d on c.oid=d.adrelid and a.attnum=d.adnum
WHERE relkind = 'r'
AND nspname=%s
AND relname=%s
AND attname=%s;
SQL;
$table = $db->tableName($table, 'raw');
$res = $db->query(sprintf($q, $db->addQuotes($db->getCoreSchema()), $db->addQuotes($table), $db->addQuotes($field)));
$row = $db->fetchObject($res);
if (!$row) {
return null;
}
$n = new PostgresField();
$n->type = $row->typname;
$n->nullable = $row->attnotnull == 'f';
$n->name = $field;
$n->tablename = $table;
$n->max_length = $row->attlen;
$n->deferrable = $row->deferrable == 't';
$n->deferred = $row->deferred == 't';
$n->conname = $row->conname;
$n->has_default = $row->atthasdef === 't';
$n->default = $row->adsrc;
return $n;
}
示例5: __getResults
private static function __getResults()
{
global $wgLang;
wfProfileIn(__METHOD__);
/* main query */
$aResult = array();
$aFields = array('/* BLOGS */ rev_page as page_id', 'page_namespace', 'page_title', 'min(rev_timestamp) as create_timestamp', 'unix_timestamp(rev_timestamp) as timestamp', 'rev_timestamp', 'min(rev_id) as rev_id', 'rev_user');
$res = self::$dbr->select(array_map(array(self::$dbr, 'tableName'), self::$aTables), $aFields, self::$aWhere, __METHOD__, self::__makeDBOrder());
while ($oRow = self::$dbr->fetchObject($res)) {
if (class_exists('ArticleCommentList')) {
$oComments = ArticleCommentList::newFromText($oRow->page_title, $oRow->page_namespace);
$iCount = $oComments ? $oComments->getCountAllNested() : 0;
} else {
$iCount = 0;
}
/* username */
$oTitle = Title::newFromText($oRow->page_title, $oRow->page_namespace);
$sUsername = "";
if (!$oTitle instanceof Title) {
continue;
}
$username = BlogArticle::getOwner($oTitle);
$oRevision = Revision::newFromTitle($oTitle);
$aResult[$oRow->page_id] = array("page" => $oRow->page_id, "namespace" => $oRow->page_namespace, "title" => $oRow->page_title, "page_touched" => !is_null($oRevision) ? $oRevision->getTimestamp() : $oTitle->getTouched(), "rev_timestamp" => $oRow->rev_timestamp, "timestamp" => $oRow->timestamp, "username" => isset($username) ? $username : "", "text" => self::__getRevisionText($oRow->page_id, $oRevision), "revision" => $oRow->rev_id, "comments" => $iCount, "votes" => '', "props" => BlogArticle::getProps($oRow->page_id));
// Sort by comment count for popular blog posts module
if (isset(self::$aOptions['order']) && self::$aOptions['order'] == 'page_id') {
uasort($aResult, array("BlogTemplateClass", "__sortByCommentCount"));
}
// We may need to query for 50 results but display 5
if (isset(self::$aOptions['displaycount']) && self::$aOptions['displaycount'] != self::$aOptions['count']) {
$aResult = array_slice($aResult, 0, self::$aOptions['displaycount']);
}
}
// macbre: change for Oasis to add avatars and comments / likes data
wfRunHooks('BlogTemplateGetResults', array(&$aResult));
self::$dbr->freeResult($res);
wfProfileOut(__METHOD__);
return $aResult;
}
示例6: countItems
/**
* Count the number of items on a user's watchlist
*
* @param DatabaseBase $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);
}
示例7: fetchObject
/**
* Fetch the next row from the given result object, in object form.
* Fields can be retrieved with $row->fieldname, with fields acting like
* member variables.
*
* @return stdClass
* @throws DBUnexpectedError Thrown if the database returns an error
*/
function fetchObject()
{
return $this->db->fetchObject($this);
}
示例8: outputResults
/**
* Format and output report results using the given information plus
* OutputPage
*
* @param OutputPage $out OutputPage to print to
* @param Skin $skin User skin to use
* @param DatabaseBase $dbr Database (read) connection to use
* @param int $res Result pointer
* @param int $num Number of available result rows
* @param int $offset Paging offset
*/
protected function outputResults($out, $skin, $dbr, $res, $num, $offset)
{
global $wgContLang;
if ($num > 0) {
$html = array();
if (!$this->listoutput) {
$html[] = $this->openList($offset);
}
# $res might contain the whole 1,000 rows, so we read up to
# $num [should update this to use a Pager]
for ($i = 0; $i < $num && ($row = $dbr->fetchObject($res)); $i++) {
$line = $this->formatResult($skin, $row);
if ($line) {
$attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
$html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
}
}
# Flush the final result
if ($this->tryLastResult()) {
$row = null;
$line = $this->formatResult($skin, $row);
if ($line) {
$attr = isset($row->usepatrol) && $row->usepatrol && $row->patrolled == 0 ? ' class="not-patrolled"' : '';
$html[] = $this->listoutput ? $line : "<li{$attr}>{$line}</li>\n";
}
}
if (!$this->listoutput) {
$html[] = $this->closeList();
}
$html = $this->listoutput ? $wgContLang->listToText($html) : implode('', $html);
$out->addHTML($html);
}
}
示例9: formatResults
/**
* @param DatabaseBase $db
* @param $res
* @param $query
* @param $redirects
* @param $results
* @param $exactMatchRow
*
* @author dymsza
*/
private static function formatResults($db, $res, $query, &$redirects, &$results, &$exactMatchRow)
{
global $wgLinkSuggestLimit;
while (($row = $db->fetchObject($res)) && count($results) < $wgLinkSuggestLimit) {
if (strtolower($row->page_title) == $query) {
$exactMatchRow = $row;
continue;
}
$titleFormatted = self::formatTitle($row->page_namespace, $row->page_title);
if ($row->page_is_redirect == 0) {
if (!in_array($titleFormatted, $results)) {
$results[] = $titleFormatted;
}
$flippedRedirs = array_flip($redirects);
if (isset($flippedRedirs[$titleFormatted])) {
unset($redirects[$flippedRedirs[$titleFormatted]]);
}
} else {
$redirTitleFormatted = self::formatTitle($row->rd_namespace, $row->rd_title);
if (!in_array($redirTitleFormatted, $results)) {
$results[] = $redirTitleFormatted;
$redirects[$titleFormatted] = $redirTitleFormatted;
}
}
}
}