Hi
I would like to retrive the ID (auto-incrementfield) of the record that I have just insreted into the database..
I am writing a DB Class function which will try to insert a new record, if it successeded will return a record object that has the id varibale set to the new ID. If it failed to insert the new record it'll return false.
Retriving the ID after a new insertion
Moderator: General Moderators
- greenhorn666
- Forum Commoner
- Posts: 87
- Joined: Thu Aug 14, 2003 7:14 am
- Location: Brussels, Belgium
This depends on your DB backend...
- mysql: mysql_insert_id()
- postgresql: pg_last_oid()
- On msSQL (sybase) you'll have to query like:
- mysql: mysql_insert_id()
- postgresql: pg_last_oid()
- On msSQL (sybase) you'll have to query like:
Code: Select all
$id = mssql_result(mssql_query("SELECT @@IDENTITY AS id"), 0, "id");