/** * Returns the next free id in a sequence * * @param string $seq_name name of the sequence * @param boolean $ondemand when true, the seqence is automatically * created if it does not exist * * @return int the next id number in the sequence. * A DB_Error object on failure. * * @see DB_common::createSequence(), DB_common::dropSequence(), * DB_common::getSequenceName() */ function nextId($seq_name, $ondemand = true) { $sqn = $this->getSequenceName($seq_name); if ($ondemand) { $tables = $this->getTables(); if (DB::isError($tables)) { return $tables; } if (!in_array($sqn, $tables)) { $res = $this->createSequence($seq_name); if (DB::isError($res)) { return $res; } } } $res = $this->query("INSERT INTO " . $sqn . " VALUES (NULL)"); if (DB::isError($res)) { return $res; } return sqlite3_last_insert_rowid($this->connection); }
/** * Returns the latest INSERT_ID of an SQL INSERT INTO command, for auto-increment columns * * @access public * @return int Value of the auto-increment column */ function serendipity_db_insert_id() { global $serendipity; return sqlite3_last_insert_rowid($serendipity['dbConn']); }
function last_insert_id() { return $this->db ? sqlite3_last_insert_rowid($this->db) : FALSE; }
<?php /* * you may need this line, depending on how you compile * this extension. */ dl('sqlite3.so'); /* * create a SQLite3 handle. * * Note: in-memory database are created by the magic keyword ":memory:" * */ $db = sqlite3_open(":memory:"); if (!$db) { die("Could not create in-memory database.."); } /* * create a simple test and insert some values.. */ $ret = sqlite3_exec($db, "CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER);"); if (!$ret) { die(sqlite3_error($db)); } sqlite3_exec($db, "INSERT INTO test (name,age) VALUES ('michael',32)"); echo "last rowid inserted : " . sqlite3_last_insert_rowid($db) . "\n"; sqlite3_exec($db, "INSERT INTO test (name,age) VALUES ('bob',27)"); echo "last rowid inserted : " . sqlite3_last_insert_rowid($db) . "\n"; sqlite3_exec($db, "INSERT INTO test (name,age) VALUES ('martin',12)"); echo "last rowid inserted : " . sqlite3_last_insert_rowid($db) . "\n"; sqlite3_close($db);
public function lastInsertRowID() { return sqlite3_last_insert_rowid($this->conn); }