Page 1 of 1

Retriving the ID after a new insertion

Posted: Tue Aug 19, 2003 4:48 am
by AbuAnas
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.

Posted: Tue Aug 19, 2003 5:02 am
by greenhorn666
This depends on your DB backend...

- 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");