本文整理汇总了PHP中Database::lastInsertId方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::lastInsertId方法的具体用法?PHP Database::lastInsertId怎么用?PHP Database::lastInsertId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::lastInsertId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
function save(Entity $entity)
{
$vars = get_object_vars($entity);
//print_r($vars);
if ($vars['id'] == 0) {
$vars['id'] == 'NULL';
}
$cols = array();
$values = array();
$updates = array();
foreach ($vars as $key => $value) {
$cols[] = "`{$key}`";
$values[] = ' :' . $key . ' ';
$updates[] = " `{$key}` = VALUES(`{$key}`) ";
}
$col = implode(",", $cols);
$value = implode(",", $values);
$update = implode(",", $updates);
$sql = "INSERT INTO {$this->tableName()} ({$col}) VALUES ({$value}) ON DUPLICATE KEY UPDATE {$update}";
$res = $this->db->query($sql, $vars);
if ($res === FALSE) {
return FALSE;
}
if ($entity->id == 0) {
$entity->id = $this->db->lastInsertId();
}
return $entity;
}
示例2: insert_comment
public function insert_comment($sid, $msg, $parent, $author_name, $author_email)
{
// Connect to database
try {
$handler = new Database();
// Insert comment to database
if ($parent !== 'NULL') {
$handler->beginTransaction();
// If comment has a parent begin transaction
}
$res = $handler->prepare('INSERT INTO `comment`(`sid`, `author_name`, `author_email`, `message`, `parent`) VALUES (:sid, :author_name, :author_email, :message, :parent)');
$res->execute(array(':sid' => $sid, ':author_name' => $author_name, ':author_email' => $author_email, ':message' => $msg, ':parent' => $parent));
if ($res->rowCount() !== 1) {
return false;
}
// Get cid of last comment
$cid = $handler->lastInsertId();
if ($parent !== 'NULL') {
$res = $handler->prepare('UPDATE `comment` SET `children` = 1 WHERE `cid` = :parent');
$res->execute(array(':parent' => $parent));
$handler->commit();
// Commit only if both queries succeed
}
} catch (PDOException $e) {
if ($parent !== 'NULL') {
$handler->rollback();
}
return false;
}
return $cid;
}
示例3: sendMessage
function sendMessage($id_author, $to_users, $subject, $body, $time, $thread_id = false) {
if (!is_array($to_users))
throw new Exception('$to_users must be an array');
Database::query('START TRANSACTION');
$query = 'INSERT INTO `users_messages` SET
`id_author`=' . $id_author . ',
`time`=' . $time . ',
`subject`=' . Database::escape($subject) . ',
`html`=' . Database::escape($body);
Database::query($query);
// если есть тред - пишем в тот же тред
$lastId = Database::lastInsertId();
$thread_id = $thread_id ? $thread_id : $lastId;
if ($thread_id) {
$q = array();
foreach ($to_users as $receiver_id) {
$is_new = ($receiver_id == $id_author) ? 0 : 1;
$q[] = '(' . $lastId . ',' . $thread_id . ',' . $receiver_id . ',' . $is_new . ',0)';
}
if (count($q)) {
$query = 'INSERT INTO `users_messages_index`(message_id,thread_id,id_recipient,is_new,is_deleted) VALUES ' . implode(',', $q);
Database::query($query);
}
}
Database::query('COMMIT');
}
示例4: edit_event
function edit_event()
{
$id = $_POST['id'] ? $_POST['id'] : 'NULL';
$_POST['template_id'] = max(1, (int) $_POST['template_id']);
Database::query('INSERT INTO `lib_events` SET
`id` = ' . $id . ',
`title`=' . Database::escape($_POST['title']) . ',
`male`=' . Database::escape($_POST['male']) . ',
`age_start_days`=' . Database::escape($_POST['age_start_days']) . ',
`age_end_days`=' . Database::escape($_POST['age_end_days']) . ',
`description`=' . Database::escape($_POST['description']) . ',
`template_id`=' . Database::escape($_POST['template_id']) . '
ON DUPLICATE KEY UPDATE
`title`=' . Database::escape($_POST['title']) . ',
`male`=' . Database::escape($_POST['male']) . ',
`age_start_days`=' . Database::escape($_POST['age_start_days']) . ',
`age_end_days`=' . Database::escape($_POST['age_end_days']) . ',
`description`=' . Database::escape($_POST['description']) . ',
`template_id`=' . Database::escape($_POST['template_id']) . '
');
$id = $id == 'NULL' ? Database::lastInsertId() : $id;
header('Location: /admin/event/' . $id . '/edit');
}
示例5: CreateBankProcess
public function CreateBankProcess($param)
{
parent::query('INSERT INTO dd_bank(bk_code,bk_account_branch,bk_account_name,bk_account_number) VALUE(:code,:branch,:name,:number)');
parent::bind(':code', $param['code']);
parent::bind(':branch', $param['branch']);
parent::bind(':name', $param['name']);
parent::bind(':number', $param['number']);
parent::execute();
return parent::lastInsertId();
}
示例6: CreateMatchingProcess
public function CreateMatchingProcess($param)
{
parent::query('INSERT INTO dy_place_to_tag(pt_place_id,pt_tag_id,pt_create_time,pt_update_time) VALUE(:place_id,:tag_id,:create_time,:update_time)');
parent::bind(':place_id', $param['place_id']);
parent::bind(':tag_id', $param['tag_id']);
parent::bind(':create_time', date('Y-m-d H:i:s'));
parent::bind(':update_time', date('Y-m-d H:i:s'));
parent::execute();
return parent::lastInsertId();
}
示例7: persist
public function persist()
{
$db = new Database();
if ($this->id == null) {
$db->execute('INSERT INTO followers (user, follower) VALUES (?, ?)', array($this->user, $this->follower));
$this->id = $db->lastInsertId();
} else {
$req = 'UPDATE followers SET user = ?, follower = ? WHERE id = ?';
$db->execute($req, array($this->user, $this->follower, $this->id));
}
}
示例8: persist
public function persist()
{
$db = new Database();
if ($this->id == null) {
$req = 'INSERT INTO stream_email (server, account, password, port, firstUpdate) VALUES (?, ?, ?, ?, ?)';
$db->execute($req, array($this->server, $this->account, $this->password, $this->port, $this->firstUpdate));
$this->id = $db->lastInsertId();
} else {
$req = 'UPDATE stream_email SET server = ?, account = ?, password = ?, port = ?, firstUpdate = ? WHERE id = ?';
$db->execute($req, array($this->server, $this->account, $this->password, $this->port, $this->firstUpdate, $this->id));
}
}
示例9: persist
public function persist()
{
$db = new Database();
if ($this->id == null) {
$req = 'INSERT INTO stream_category (stream, category, streamType) VALUES (?, ?, ?)';
$db->execute($req, array($this->stream, $this->category, $this->streamType));
$this->id = $db->lastInsertId();
} else {
$req = 'UPDATE stream_category SET stream = ?, category = ?, streamType = ? WHERE id = ?';
$db->execute($req, array($this->stream, $this->category, $this->streamType, $this->id));
}
}
示例10: _new
function _new()
{
$title = trim(Request::post('title'));
if (!$title) {
throw new Exception('title missed');
}
$query = 'INSERT INTO `rightholders` SET `title`=' . Database::escape($title);
Database::query($query);
@ob_end_clean();
header('Location: /admin/rightholders/' . Database::lastInsertId());
exit;
}
示例11: persist
public function persist()
{
$db = new Database();
if ($this->id == null) {
$req = 'INSERT INTO article (title, content, articleDate, streamType, url, stream_id) VALUES (?, ?, ?, ?, ?, ?)';
$db->execute($req, array($this->title, $this->content, $this->articleDate, $this->streamType, $this->url, $this->stream_id));
$this->id = $db->lastInsertId();
} else {
$req = 'UPDATE article SET title = ?, content = ?, articleDate = ?, streamType = ?, url = ?, stream_id = ? WHERE id = ?';
$db->execute($req, array($this->title, $this->content, $this->articleDate, $this->streamType, $this->url, $this->stream_id, $this->id));
}
}
示例12: persist
public function persist()
{
$db = new Database();
if ($this->id == null) {
$req = 'INSERT INTO blog (account, article) VALUES (?, ?)';
$db->execute($req, array($this->account, $this->article));
$this->id = $db->lastInsertId();
} else {
$req = 'UPDATE blog SET account = ?, article = ? WHERE id = ?';
$db->execute($req, array($this->account, $this->article, $this->id));
}
}
示例13: persist
public function persist()
{
$db = new Database();
if ($this->id == null) {
$req = 'INSERT INTO accounts (authentification, username, email, userKey, active, accountLevel, picture) VALUES (?, ?, ?, ?, ?, ?, ?)';
$db->execute($req, array($this->authentification, $this->username, $this->email, $this->userKey, $this->active, $this->accountLevel, $this->picture));
$this->id = $db->lastInsertId();
} else {
$req = 'UPDATE accounts SET authentification = ?, username = ?, email = ?, userKey = ?, active = ?, accountLevel = ?, picture = ? WHERE id = ?';
$db->execute($req, array($this->authentification, $this->username, $this->email, $this->userKey, $this->active, $this->accountLevel, $this->picture, $this->id));
}
}
示例14: add_album_relation_link
function add_album_relation_link()
{
$album_id = $_POST['album_id'];
$role = $_POST['role'];
Database::query('INSERT INTO `album_invites` SET
`album_id`=' . $album_id . ',
`inviter_user_id `=' . CurrentUser::$id . ',
`family_role`=' . $role);
$uniqid = Database::lastInsertId();
$data = array();
$data['link'] = 'http://' . Config::need('www_domain') . '/invite/' . $album_id . '/' . $role . '/' . md5($uniqid);
return $data;
}
示例15: create
/**
* Create a new DVD to the database
*
* @return mixed False if failed, admin url otherwise
*/
public function create()
{
$this->publicUrl = strtolower(urlencode($this->title));
$this->adminHash = substr(md5($this->title . time() . rand()), 0, 8);
$dbh = new Database();
$sth = $dbh->prepare("INSERT INTO " . DB_PREFIX . "dvds (title, author, email, publish_date, deadline_date, status, show_frontpage, description, public_url, admin_hash) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if (!$sth->execute(array($this->title, $this->author, $this->email, $this->publishDate, $this->deadlineDate, $this->status, $this->showFrontpage, $this->description, $this->publicUrl, $this->adminHash))) {
return false;
}
$this->id = (int) $dbh->lastInsertId();
$adminUrl = SITE_URL . '/' . $this->id . '/' . $this->publicUrl . '/' . $this->adminHash;
return $adminUrl;
}