本文整理汇总了PHP中resource::lastInsertId方法的典型用法代码示例。如果您正苦于以下问题:PHP resource::lastInsertId方法的具体用法?PHP resource::lastInsertId怎么用?PHP resource::lastInsertId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resource
的用法示例。
在下文中一共展示了resource::lastInsertId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* 插入更新数据
* @param string $sql 需要执行的sql语句
* @return int
*/
public function execute($sql)
{
$count = $this->pdo->exec($sql);
if ($count && false !== strpos($sql, 'insert')) {
return $this->pdo->lastInsertId();
}
return $count;
}
示例2: lastInsertId
/**
* Obtem o ultimo ID inserido independente do tipo de query
* @return int
*/
public static function lastInsertId()
{
if (CRUDQuery::isPDOMode()) {
return self::$conn->lastInsertId();
} elseif (CRUDQuery::isMySqliMode()) {
return mysqli_insert_id(CRUDQuery::getConn());
}
}
示例3: insert
public function insert(array $data)
{
self::prepareDataToSave($data);
$lastInsertId = 0;
$fields = implode(', ', array_keys($data));
$values = implode(', ', $data);
//echo "INSERT INTO {$this->_tableName} ({$fields}) VALUES( $values );";
$this->setSqlQuery("INSERT INTO {$this->_tableName} ({$fields}) VALUES( {$values} );")->execQuery();
$lastInsertId = $this->getNumRows() ? $this->_PDOmySQLConn->lastInsertId() : 0;
return $lastInsertId;
}
示例4: insertID
/**
* {@inheritDoc}
*
* @param string $table_name of table of last insert
* @return string the ID of the insert
*/
function insertID($table_name = "")
{
if ($table_name && $this->to_upper_dbms == "PGSQL") {
$table_name .= "_ID_SEQ";
$id = $this->pdo->lastInsertId($table_name);
if (!$id) {
//if sequence number somehow was renamed
$id = $this->pdo->lastInsertId($table_name . "1");
}
return $id;
}
return $this->pdo->lastInsertId();
}
示例5: execute
/**
* 执行写入语句
*
* @access public
* @param $sql
* @return int|false
*/
public function execute($sql)
{
$this->connect();
if (!$this->_linkId) {
return false;
}
try {
$this->_numRows = $this->_linkId->exec($sql);
} catch (PDOException $e) {
trigger_error('MySQL PDO execute error: ' . $e->getMessage() . ' [' . $sql . ']');
}
$lastInsID = $this->_linkId->lastInsertId();
return $lastInsID ? $lastInsID : $this->_numRows;
}
示例6: insertId
/**
* 获得刚插入数据的ID号
*
* @return Int
*/
function insertId()
{
if ($this->type == "PDO") {
return $this->conn->lastInsertId();
} else {
if ($this->type == "SQLite3") {
return $this->conn->lastInsertRowID();
} else {
if ($this->type == "SQLite2") {
return sqlite_last_insert_rowid($this->conn);
}
}
}
}
示例7: onCommandFeedadd
/**
* Add a Feed
*
* @param String $feed_url ToDo desc
* @param String $channel (optional)
*
* @return void
*/
public function onCommandFeedadd($feed_url, $channel = '')
{
$nick = $this->event->getNick();
if (empty($channel)) {
$channel = $this->event->getSource();
}
// Check if this feed already exists
$sql = 'SELECT COUNT(*) FROM ft_feeds WHERE feed_url = ' . $this->db->quote($feed_url) . ' AND channel = ' . $this->db->quote($channel);
if ((bool) $this->db->query($sql)->fetchColumn()) {
$this->doNotice($nick, 'This feed already exists.');
return;
}
// Get Feed
if (!($feed = $this->plugins->getPlugin('FeedTicker')->getFeed($feed_url))) {
$this->doNotice($nick, 'Fail to get data from this feed.');
return;
}
// Parse Feed
$FeedParser = $this->plugins->getPlugin('FeedParser');
if ($f = $FeedParser->parseFeed($feed['content'], $feed['header'])) {
try {
$defaultDelay = intval($this->getConfig('FeedTicker.defaultDelay', 300));
if ($defaultDelay < 60) {
$defaultDelay = 60;
}
$q = $this->db->prepare('INSERT INTO ft_feeds (
updated, etag, delay, channel, title,
description, link, feed_url, active
) VALUES (
:updated, :etag, :delay, :channel,
:title, :description, :link, :feed_url, :active
)');
$q->execute(array(':updated' => $f->updated, ':etag' => $f->etag, ':delay' => $defaultDelay, ':channel' => $channel, ':title' => $f->title, ':description' => $f->description, ':link' => $f->link, ':feed_url' => $feed_url, ':active' => true));
} catch (PDOException $e) {
echo 'ERROR(FeedTicker): ' . $e . PHP_EOL;
}
if ($rowid = $this->db->lastInsertId()) {
$this->doNotice($nick, "Done!");
$this->addItems($rowid, $f->items);
$this->feeds = $this->getAllFeeds();
} else {
$this->doNotice($nick, 'Bad things happened. Feed not saved.');
return;
}
} else {
$this->doNotice($nick, "This feed is not valid/suported or is empty!");
}
}
示例8: handleRemind
/**
* Handles the tell/remind command (stores the message)
*
* @param string $recipient name of the recipient
* @param string $message message to store
*
* @return void
*/
protected function handleRemind($recipient, $message)
{
// Don't do anything if we are only responding to targeted reminders and this isn't a targeted message.
if ($this->onlyTargetedReminders && !$this->plugins->message->isTargetedMessage()) {
return;
}
$source = $this->getEvent()->getSource();
$nick = $this->getEvent()->getNick();
$myself = $this->getConnection()->getNick();
if ($myself == $recipient) {
$this->doPrivmsg($source, 'You can\'t send reminders to me.');
return;
}
if (!$this->getEvent()->isInChannel()) {
$this->doPrivmsg($source, 'Reminders must be requested in-channel.');
return;
}
$q = $this->db->prepare('INSERT INTO remind
(
time,
channel,
recipient,
sender,
message
)
VALUES
(
:time,
:channel,
:recipient,
:sender,
:message
)');
try {
$q->execute(array('time' => date(DATE_RFC822), 'channel' => $source, 'recipient' => strtolower($recipient), 'sender' => strtolower($nick), 'message' => $message));
} catch (PDOException $e) {
}
if ($rowid = $this->db->lastInsertId()) {
$this->doPrivmsg($source, 'ok, ' . $nick . ', message stored');
} else {
$this->doPrivmsg($source, $nick . ': bad things happened. Message not saved.');
return;
}
if ($this->keepListInMemory) {
$this->msgStorage[$source][strtolower($recipient)] = $rowid;
}
}
示例9: handleRemind
/**
* Handles the tell/remind command (stores the message)
*
* @param string $recipient name of the recipient
* @param string $message message to store
*
* @return void
*/
protected function handleRemind($recipient, $message)
{
$source = $this->getEvent()->getSource();
$nick = $this->getEvent()->getNick();
if (!$this->getEvent()->isInChannel()) {
$this->doPrivmsg($source, 'Reminders must be requested in-channel.');
return;
}
$q = $this->db->prepare('INSERT INTO remind
(
time,
channel,
recipient,
sender,
message
)
VALUES
(
:time,
:channel,
:recipient,
:sender,
:message
)');
try {
$q->execute(array('time' => date(DATE_RFC822), 'channel' => $source, 'recipient' => strtolower($recipient), 'sender' => strtolower($nick), 'message' => $message));
} catch (PDOException $e) {
}
if ($rowid = $this->db->lastInsertId()) {
$this->doPrivmsg($source, 'ok, ' . $nick . ', message stored');
} else {
$this->doPrivmsg($source, $nick . ': bad things happened. Message not saved.');
return;
}
if ($this->keepListInMemory) {
$this->msgStorage[$source][strtolower($recipient)] = $rowid;
}
}
示例10: lastInsertId
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* @return string
*/
public function lastInsertId()
{
$this->_connect();
return $this->connection->lastInsertId();
}
示例11: lastInsertId
/**
* lasst insert id
* @todo pgsql support
* @param resource $connResource
* @return int
*/
public function lastInsertId($connResource)
{
return $connResource->lastInsertId();
}
示例12: getInsertId
/**
* Get the ID generated from the previous INSERT operation
*
* @return int
* @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector.
*/
public function getInsertId()
{
$this->deprecated();
return $this->conn->lastInsertId();
}
示例13: post
/**
* Execute a POST request.
*/
function post()
{
if ($this->table && $this->uid) {
if ($this->requestData) {
$primary = $this->getPrimaryKeys();
if ($primary && count($primary) == count($this->uid)) {
// update a row
$pairs = $this->parseRequestData();
$values = '';
foreach ($pairs as $column => $data) {
$values .= '`' . $column . '` = "' . $this->db->escape($data) . '", ';
}
$values = substr($values, 0, -2);
$where = '';
foreach ($primary as $key => $pri) {
$where .= $pri . ' = \'' . $this->uid[$key] . '\' AND ';
}
$where = substr($where, 0, -5);
$resource = $this->db->updateRow($this->table, $values, $where);
if ($resource) {
if ($this->db->numAffected() > 0) {
$values = array();
foreach ($pairs as $column => $data) {
$field = array('field' => $column, 'value' => $data);
if (substr($column, -strlen($this->config['database']['foreignKeyPostfix'])) == $this->config['database']['foreignKeyPostfix']) {
$field['xlink'] = $this->config['settings']['baseURL'] . '/' . substr($column, 0, -strlen($this->config['database']['foreignKeyPostfix'])) . '/' . $data . '/';
}
$values[] = $field;
}
$this->output['row'] = $values;
$this->generateResponseData();
} else {
$this->badRequest();
}
} else {
$this->internalServerError();
}
} else {
$this->badRequest();
}
} else {
$this->lengthRequired();
}
} elseif ($this->table) {
// insert a row without a uid
if ($this->requestData) {
$pairs = $this->parseRequestData();
$values = join('", "', $pairs);
$names = join('`, `', array_keys($pairs));
$resource = $this->db->insertRow($this->table, $names, $values);
if ($resource) {
if ($this->db->numAffected() > 0) {
$this->created($this->config['settings']['baseURL'] . '/' . $this->table . '/' . $this->db->lastInsertId() . '/');
} else {
$this->badRequest();
}
} else {
$this->internalServerError();
}
} else {
$this->lengthRequired();
}
} else {
$this->methodNotAllowed('GET, HEAD');
}
}
示例14: insertPDO
/**
*
* @param string $tabla
* @param array $data
* @param resource $link_identifier
* @return array
*/
function insertPDO($tabla, $data, $link_identifier = null)
{
$names = $values = array();
$tabla = (string) $tabla;
$data = (array) $data;
$return = array('success' => false, 'lastInsertId' => 0);
if (!empty($tabla) && !empty($data)) {
foreach ($data as $key => $value) {
$names[] = (string) $key;
$values[] = is_int($value) ? $value : "'{$value}'";
}
$namesString = implode(', ', $names);
$valuesString = implode(', ', $values);
$sql = "INSERT INTO {$tabla} ( {$namesString} ) VALUES( {$valuesString} )";
$insert = $link_identifier->prepare($sql);
$insert->execute();
$return['success'] = $insert;
$return['lastInsertId'] = $link_identifier->lastInsertId();
}
return $return;
}
示例15: insertId
/**
* Get last inserted id of the last query
*/
public function insertId()
{
return (int) $this->connection->lastInsertId();
}