Skip to content

Commit

Permalink
Add lastId Method (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
schengawegga authored Nov 4, 2023
1 parent 7e1ced2 commit 90010c5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions DB/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
23 changes: 23 additions & 0 deletions DB/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
23 changes: 23 additions & 0 deletions DB/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 90010c5

Please sign in to comment.