Accessing Last Inserted Row In Mysql
On my db-server i am inserting data in a table having a auto increment field say 'id'. Now i want to use the value of this last inserted 'id' in subsequent steps. I can use this:-
Solution 1:
Use this
mysql_insert_id(&mysql);
as its basic structure are
mysql_insert_id ([ resource $link_identifier = NULL ] )
Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).
or in mysql use
SELECT LAST_INSERT_ID();
here is the ref links
http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
Solution 2:
call LAST_INSERT_ID()
function immediately after insertion and save id somewhere.
Solution 3:
Solution 4:
Use this mysql_insert_id()
It returns the AUTO_INCREMENT ID generated from the previous INSERT operation.
This function returns 0 if the previous operation does not generate an AUTO_INCREMENT ID, or FALSE on MySQL connection failure.
Solution 5:
you can get the id if you call LAST_INSERT_ID() function immediately after insertion and then you can use it.
Post a Comment for "Accessing Last Inserted Row In Mysql"