lastInsertId -- DB
| From: | Mick van der Most van Spijk | Date: | Thu, 20 Jun 2002 18:07:44 +0000 |
| Subject: | lastInsertId -- DB | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-7244@lists.php.net to get a copy of this message | ||
Hi all,
For insert purposes i have build in the mysql.php of DB the very simple function lastInsertId().
This is done for the following reason: after an update i needed the id of the row that was inserted.
With mysql this works and it gives me the id generated from my id auto_increment field.
the following code i added to common.php:
// {{{ lastInsertId()
function lastInsertId()
{
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
// }}}
the following code i added to mysql.php
// {{{ lastInsertId()
/** Get the id of the last insert
*
* @access public
*
* return int id (auto_increment) of last insert
*/
function lastInsertId()
{
$id = @mysql_insert_id();
if ($id === null) {
return $this->mysqlRaiseError();
}
return $id;
}
// }}}
When the is need for this function im willing to write the postgres version also.
Hope this is enough info.
Greetz mcvdmvs