本文整理汇总了PHP中DatabaseBase::insertId方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseBase::insertId方法的具体用法?PHP DatabaseBase::insertId怎么用?PHP DatabaseBase::insertId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseBase
的用法示例。
在下文中一共展示了DatabaseBase::insertId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertOn
/**
* Insert a new empty page record for this article.
* This *must* be followed up by creating a revision
* and running $this->updateRevisionOn( ... );
* or else the record will be left in a funky state.
* Best if all done inside a transaction.
*
* @param DatabaseBase $dbw
* @return int|bool The newly created page_id key; false if the title already existed
*/
public function insertOn($dbw)
{
$page_id = $dbw->nextSequenceValue('page_page_id_seq');
$dbw->insert('page', array('page_id' => $page_id, 'page_namespace' => $this->mTitle->getNamespace(), 'page_title' => $this->mTitle->getDBkey(), 'page_restrictions' => '', 'page_is_redirect' => 0, 'page_is_new' => 1, 'page_random' => wfRandom(), 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, 'page_len' => 0), __METHOD__, 'IGNORE');
$affected = $dbw->affectedRows();
if ($affected) {
$newid = $dbw->insertId();
$this->mId = $newid;
$this->mTitle->resetArticleID($newid);
return $newid;
} else {
return false;
}
}
示例2: initializeDbBasicData
/**
* Helper function to initializeDbForNewAd()
*
* @param DatabaseBase $db
*/
protected function initializeDbBasicData($db)
{
$db->insert('pr_ads', array('ad_name' => $this->name), __METHOD__);
$this->id = $db->insertId();
}
示例3: insertOn
/**
* Insert a new revision into the database, returning the new revision ID
* number on success and dies horribly on failure.
*
* @param DatabaseBase $dbw (master connection)
* @throws MWException
* @return int
*/
public function insertOn($dbw)
{
global $wgDefaultExternalStore, $wgContentHandlerUseDB;
$this->checkContentModel();
$data = $this->mText;
$flags = self::compressRevisionText($data);
# Write to external storage if required
if ($wgDefaultExternalStore) {
// Store and get the URL
$data = ExternalStore::insertToDefault($data);
if (!$data) {
throw new MWException("Unable to store text to external storage");
}
if ($flags) {
$flags .= ',';
}
$flags .= 'external';
}
# Record the text (or external storage URL) to the text table
if ($this->mTextId === null) {
$old_id = $dbw->nextSequenceValue('text_old_id_seq');
$dbw->insert('text', array('old_id' => $old_id, 'old_text' => $data, 'old_flags' => $flags), __METHOD__);
$this->mTextId = $dbw->insertId();
}
if ($this->mComment === null) {
$this->mComment = "";
}
# Record the edit in revisions
$rev_id = $this->mId !== null ? $this->mId : $dbw->nextSequenceValue('revision_rev_id_seq');
$row = array('rev_id' => $rev_id, 'rev_page' => $this->mPage, 'rev_text_id' => $this->mTextId, 'rev_comment' => $this->mComment, 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, 'rev_user' => $this->mUser, 'rev_user_text' => $this->mUserText, 'rev_timestamp' => $dbw->timestamp($this->mTimestamp), 'rev_deleted' => $this->mDeleted, 'rev_len' => $this->mSize, 'rev_parent_id' => $this->mParentId === null ? $this->getPreviousRevisionId($dbw) : $this->mParentId, 'rev_sha1' => $this->mSha1 === null ? Revision::base36Sha1($this->mText) : $this->mSha1);
if ($wgContentHandlerUseDB) {
// NOTE: Store null for the default model and format, to save space.
// XXX: Makes the DB sensitive to changed defaults.
// Make this behavior optional? Only in miser mode?
$model = $this->getContentModel();
$format = $this->getContentFormat();
$title = $this->getTitle();
if ($title === null) {
throw new MWException("Insufficient information to determine the title of the " . "revision's page!");
}
$defaultModel = ContentHandler::getDefaultModelFor($title);
$defaultFormat = ContentHandler::getForModelID($defaultModel)->getDefaultFormat();
$row['rev_content_model'] = $model === $defaultModel ? null : $model;
$row['rev_content_format'] = $format === $defaultFormat ? null : $format;
}
$dbw->insert('revision', $row, __METHOD__);
$this->mId = $rev_id !== null ? $rev_id : $dbw->insertId();
// Assertion to try to catch T92046
if ((int) $this->mId === 0) {
throw new UnexpectedValueException('After insert, Revision mId is ' . var_export($this->mId, 1) . ': ' . var_export($row, 1));
}
Hooks::run('RevisionInsertComplete', array(&$this, $data, $flags));
return $this->mId;
}