diff --git a/DB/common.php b/DB/common.php index 2c57cd0..458f0a2 100644 --- a/DB/common.php +++ b/DB/common.php @@ -1808,6 +1808,23 @@ function nextId($seq_name, $ondemand = true) return $this->raiseError(DB_ERROR_NOT_CAPABLE); } + // }}} + // {{{ lastId() + + /** + * Returns the row ID of the most recent INSERT into the database + * + * @param string $link_identifier DBMS link identifier + * + * @return int the row ID of the most recent INSERT into the database. + * If no successful INSERTs into rowid tables have ever + * occurred on this database connection then returns 0. + */ + function lastId($link_identifier = null) + { + return $this->raiseError(DB_ERROR_NOT_CAPABLE); + } + // }}} // {{{ createSequence() diff --git a/DB/mysql.php b/DB/mysql.php index 503ecc0..ca8a8b1 100644 --- a/DB/mysql.php +++ b/DB/mysql.php @@ -653,6 +653,29 @@ function nextId($seq_name, $ondemand = true) return $this->raiseError($result); } + // }}} + // {{{ lastId() + + /** + * Returns the row ID of the most recent INSERT into the database + * + * @param string $link_identifier mysql link identifier + * + * @return int the row ID of the most recent INSERT into the database. + * If no successful INSERTs into rowid tables have ever + * occurred on this database connection then returns 0. + * + * @see DB_common::lastID() + */ + function lastId($link_identifier = null) + { + $id = mysql_insert_id($link_identifier); + if(empty($id) || !is_int($id)) { + return 0; + } + return $id; + } + // }}} // {{{ createSequence() diff --git a/DB/mysqli.php b/DB/mysqli.php index d8a5851..21a41bc 100644 --- a/DB/mysqli.php +++ b/DB/mysqli.php @@ -746,6 +746,29 @@ function nextId($seq_name, $ondemand = true) return $this->raiseError($result); } + // }}} + // {{{ lastId() + + /** + * Returns the row ID of the most recent INSERT into the database + * + * @param string $link_identifier mysqli link identifier + * + * @return int the row ID of the most recent INSERT into the database. + * If no successful INSERTs into rowid tables have ever + * occurred on this database connection then returns 0. + * + * @see DB_common::lastID() + */ + function lastId($link_identifier = null) + { + $id = $this->connection->insert_id(); + if(empty($id) || !is_int($id)) { + return 0; + } + return $id; + } + /** * Creates a new sequence *