Reputation: 35
I have a customer table storing details of all customers. The customer_id is the primary key of customer table. I need to get the value of the recently inserted customer's customer_id.How can I get it? Please help me.What is the syntax for it?
Upvotes: 0
Views: 68
Reputation: 22741
Using PHP, you can get last inserted id by using below mentioned two method based on the mysql
or mysqli
,
mysqli:
mysqli_insert_id($con);
mysql:
mysql_insert_id();
Upvotes: 0
Reputation: 16544
You may try this:
SELECT LAST_INSERT_ID();
It returns a BIGINT (64-bit) value representing the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT statement to affect such a column. For example, after inserting a row that generates an AUTO_INCREMENT value, you can get the value like this:
mysql> SELECT LAST_INSERT_ID(); -> 195
Reference: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id
and http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.html
Upvotes: 1