本文整理汇总了PHP中DBManager::last_inserted_id方法的典型用法代码示例。如果您正苦于以下问题:PHP DBManager::last_inserted_id方法的具体用法?PHP DBManager::last_inserted_id怎么用?PHP DBManager::last_inserted_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBManager
的用法示例。
在下文中一共展示了DBManager::last_inserted_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Salva il report nel database.
*
* se INSERT: crea una nuova tupla in Report.
* se UPDATE: non fa nulla. Non si può modificare un report.
*/
function save()
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
$table = Query::getDBSchema()->getTable(TABLE_RESOURCE);
$data = array(RESOURCE_OWNER => $this->getOwner(), RESOURCE_PATH => $this->getPath(), RESOURCE_TYPE => $this->getType());
$rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
//echo "<br />" . serialize($rs); //DEBUG
if ($db->affected_rows() == 1) {
$this->setID($db->last_inserted_id());
//echo "<br />" . $this; //DEBUG
return $this->getID();
} else {
$db->display_error("Resource::save()");
}
} else {
$db->display_connect_error("Resource::save()");
}
return false;
}
示例2: save
function save()
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineUserColumns();
$table = Query::getDBSchema()->getTable(TABLE_USER);
$data = array();
if (isset($this->avatar)) {
$data[USER_AVATAR] = $this->getAvatar();
}
if (isset($this->birthday)) {
$data[USER_BIRTHDAY] = date("Y/m/d", $this->getBirthday());
}
if (isset($this->birthplace)) {
$data[USER_BIRTHPLACE] = $this->getBirthplace();
}
if (isset($this->email)) {
$data[USER_E_MAIL] = $this->getEMail();
}
if (isset($this->gender)) {
$data[USER_GENDER] = $this->getGender();
}
if (isset($this->hobbies)) {
$data[USER_HOBBIES] = $this->getHobbies();
}
if (isset($this->job)) {
$data[USER_JOB] = $this->getJob();
}
if (isset($this->livingPlace)) {
$data[USER_LIVINGPLACE] = $this->getLivingPlace();
}
if (isset($this->name)) {
$data[USER_NAME] = $this->getName();
}
if (isset($this->nickname)) {
$data[USER_NICKNAME] = $this->getNickname();
}
if (isset($this->password)) {
$data[USER_PASSWORD] = $this->getPassword();
}
if (isset($this->role)) {
$data[USER_ROLE] = $this->getRole();
}
if (isset($this->surname)) {
$data[USER_SURNAME] = $this->getSurname();
}
if (isset($this->visible)) {
$data[USER_VISIBLE] = $this->getVisible() ? 1 : 0;
}
$db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
if ($db->affected_rows() == 1) {
$this->setID($db->last_inserted_id());
$db->execute(Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(USER_ID), Operator::EQUAL, $this->getID())), array()));
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
$this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[USER_CREATION_DATE])));
return $this;
} else {
$db->display_error("User::save()");
}
} else {
$db->display_error("User::save()");
}
} else {
$db->display_connect_error("User::save()");
}
return false;
}
示例3: save
function save()
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineMailColumns();
$table = Query::getDBSchema()->getTable(TABLE_MAIL);
$data = array();
if (isset($this->subject) && !is_null($this->getSubject())) {
$data[MAIL_SUBJECT] = $this->getSubject();
}
if (isset($this->from) && !is_null($this->getFrom())) {
$data[MAIL_FROM] = intval($this->getFrom());
}
if (isset($this->to) && !is_null($this->getTo())) {
$data[MAIL_TO] = $this->getTo();
}
if (isset($this->text) && !is_null($this->getText())) {
$data[MAIL_TEXT] = $this->getText();
}
if (isset($this->repliesTo) && !is_null($this->getRepliesTo())) {
$data[MAIL_REPLIES_TO] = intval($this->getRepliesTo());
}
$rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
//echo "<br />" . $db->affected_rows(); //DEBUG
if ($db->affected_rows() == 1) {
$this->setID(intval($db->last_inserted_id()));
//echo "<br />" . serialize($this->ID); //DEBUG
$rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(MAIL_ID), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
$this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[MAIL_CREATION_DATE])));
//echo "<br />" . serialize($row[MAIL_CREATION_DATE]); //DEBUG
//inserisce il messaggio nelle mailbox dei $to
$toes = explode("|", $this->getTo());
//echo serialize($toes); //DEBUG
require_once "mail/MailManager.php";
for ($i = 0; $i < count($toes); $i++) {
$dir = MailManager::loadDirectoryFromName(MAILBOX, intval($toes[$i]));
MailManager::addMailToDir($this, $dir);
}
//echo "<br />" . $this; //DEBUG
return $this;
} else {
$db->display_error("Mail::save()");
}
} else {
$db->display_error("Mail::save()");
}
} else {
$db->display_connect_error("Mail::save()");
}
return false;
}
示例4: save
/**
* Salva il post e le sue dipendenze nel database.
* Le dipendenze salvate sono quelle che dipendono dall'autore ovvero: tag e categorie.
* Potrebbe salvare alcune tuple in Tag.
*
* @return: ID della tupla inserita (o aggiornata), FALSE se c'è un errore.
*/
function save()
{
require_once "post/PostCommon.php";
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
definePostColumns();
$table = Query::getDBSchema()->getTable(TABLE_POST);
$data = array(POST_TYPE => $this->getType());
if (isset($this->title) && !is_null($this->getTitle())) {
$data[POST_TITLE] = $this->getTitle();
}
if (isset($this->subtitle) && !is_null($this->getSubtitle())) {
$data[POST_SUBTITLE] = $this->getSubtitle();
}
if (isset($this->headline) && !is_null($this->getHeadline())) {
$data[POST_HEADLINE] = $this->getHeadline();
}
if (isset($this->tags) && !is_null($this->getTags())) {
$data[POST_TAGS] = $this->getTags();
}
if (isset($this->categories) && !is_null($this->getCategories())) {
// check sulle categorie, eliminazione di quelle che non esistono nel sistema, se vuoto inserimento di quella di default
$new_cat = CategoryManager::filterWrongCategories(explode(",", $this->getCategories()));
if (!isset($this->categories) || is_null($this->getCategories()) || count($new_cat) == 0) {
$new_cat[] = self::DEFAULT_CATEGORY;
}
$this->setCategories(Filter::arrayToText($new_cat));
$data[POST_CATEGORIES] = $this->getCategories();
}
if (isset($this->content) && !is_null($this->getContent())) {
if ($this->type == "post" || $this->type == "news" || $this->type == "videoreportage") {
$data[POST_CONTENT] = $this->getContent();
} else {
$data[POST_CONTENT] = serialize($this->getContent());
}
}
if (isset($this->visible) && !is_null($this->isVisible())) {
$data[POST_VISIBLE] = $this->isVisible() ? 1 : 0;
}
if (isset($this->author) && !is_null($this->getAuthor())) {
$data[POST_AUTHOR] = $this->getAuthor();
}
if (isset($this->place) && !is_null($this->getPlace())) {
$data[POST_PLACE] = $this->getPlace();
}
$data[POST_PERMALINK] = $this->getPermalink();
if (self::permalinkExists($this->getPermalink())) {
//finché esiste già un permalink del genere, ne genero uno radfom.
$data[POST_PERMALINK] = $this->getPermalink() . "(" . rand(1024, $_SERVER["REQUEST_TIME"]) . ")";
}
$data[POST_CREATION_DATE] = date("Y-m-d G:i:s", $_SERVER["REQUEST_TIME"]);
$rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
//echo "<br />" . $db->affected_rows(); //DEBUG
if ($db->affected_rows() == 1) {
$this->setID($db->last_inserted_id());
//echo "<br />" . serialize($this->ID); //DEBUG
$rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(POST_ID), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
//echo "<br />" . serialize($rs); //DEBUG
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
//echo "<br />" . $row; //DEBUG
$this->setPermalink($row[POST_PERMALINK]);
$this->setModificationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[POST_CREATION_DATE])));
//salvo i tag che non esistono
if (isset($data[POST_TAGS]) && !is_null($data[POST_TAGS]) && trim($data[POST_TAGS]) != "") {
TagManager::createTags(explode(",", $data[POST_TAGS]));
}
//echo "<br />" . serialize($row[POST_CREATION_DATE]); //DEBUG
//echo "<br />" . $this; //DEBUG
return $this->ID;
} else {
$db->display_error("Post::save()");
}
} else {
$db->display_error("Post::save()");
}
} else {
$db->display_connect_error("Post::save()");
}
return false;
}
示例5: save
/**
* Salva il contest e le sue dipendenze nel database.
*
* @return: ID della tupla inserita, FALSE se c'è un errore.
*/
function save()
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineContestColumns();
$table = Query::getDBSchema()->getTable(TABLE_CONTEST);
$data = array();
if (isset($this->title) && !is_null($this->getTitle())) {
$data[CONTEST_TITLE] = $this->getTitle();
}
if (isset($this->description) && !is_null($this->getDescription())) {
$data[CONTEST_DESCRIPTION] = $this->getDescription();
}
if (isset($this->rules) && !is_null($this->getRules())) {
$data[CONTEST_RULES] = $this->getRules();
}
if (isset($this->prizes) && !is_null($this->getPrizes())) {
$data[CONTEST_PRIZES] = $this->getPrizes();
}
if (isset($this->start) && !is_null($this->getStart())) {
$data[CONTEST_START] = date("Y/m/d G:i:s", $this->getStart());
}
if (isset($this->end) && !is_null($this->getEnd())) {
$data[CONTEST_END] = date("Y/m/d G:i:s", $this->getEnd());
}
if (isset($this->subscriberType) && !is_null($this->getSubscriberType())) {
$data[CONTEST_TYPE_OF_SUBSCRIBER] = $this->getSubscriberType();
}
$rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
//echo "<br />" . serialize($rs); //DEBUG
if ($db->affected_rows() == 1) {
$this->setID($db->last_inserted_id());
//echo "<br />" . serialize($this->ID); //DEBUG
//echo "<br />" . $this; //DEBUG
return $this->ID;
} else {
$db->display_error("Contest::save()");
}
} else {
$db->display_connect_error("Contest::save()");
}
return false;
}
示例6: save
/**
* Salva il commento nel database.
*
* @param savingMode: uno dei valori della classe SavingMode.
* se INSERT: crea una nuova tupla in Post.
* se UPDATE: confronta il Post con quello presente nel database e aggiorna le differenze.
*/
function save()
{
require_once "query.php";
$db = new DBManager();
if (!$db->connect_errno()) {
define_tables();
defineCommentColumns();
$table = Query::getDBSchema()->getTable(TABLE_COMMENT);
$data = array(COMMENT_COMMENT => $this->getComment(), COMMENT_POST => $this->getPost(), COMMENT_AUTHOR => $this->getAuthor());
$rs = $db->execute($s = Query::generateInsertStm($table, $data), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
//echo "<br />" . serialize($rs); //DEBUG
if ($db->affected_rows() == 1) {
$this->ID = $db->last_inserted_id();
//echo "<br />" . serialize($this->ID); //DEBUG
$rs = $db->execute($s = Query::generateSelectStm(array($table), array(), array(new WhereConstraint($table->getColumn(COMMENT_ID), Operator::EQUAL, $this->getID())), array()), $table->getName(), $this);
//echo "<br />" . $s; //DEBUG
if ($db->num_rows() == 1) {
$row = $db->fetch_result();
$this->setCreationDate(date_timestamp_get(date_create_from_format("Y-m-d G:i:s", $row[COMMENT_CREATION_DATE])));
//echo "<br />" . serialize($row[COMMENT_CREATION_DATE]); //DEBUG
//echo "<br />" . $this; //DEBUG
return $this->ID;
} else {
$db->display_error("Comment::save()");
}
} else {
$db->display_error("Comment::save()");
}
} else {
$db->display_connect_error("Comment::save()");
}
return false;
}