Category Archives: mysql

PHP: Just got into mysql_insert_id() is very useful.

Long ago I have been programming with PHP but I am having problem in getting the inserted key for the new record that I have just inserted to my database.

 

My turn around was to query the same data that I have inserted. Recently, it just to  my head if there is a function on the net that perform the said task. And poof there it is. mysql_insert_id();

Usage

1. Perform an insert query. ea. INSERT INTO name(`name`) VALUES(‘NAME’)

2. Use the function to get the primary-auto-increment key. $id = mysql_insert_id();

Thats it you have get the key of your inserted record.

 

Hope it help you.