Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lastId Method #19

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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