What is mysql insert id in PHP

In this article I am going to explain about mysql_insert_id function in PHP.
  • 1555

PHP mysql_insert_id() Function

The PHP mysql_insert_id function is used to returns auto_increment generated from the previous insert operation.

Syntax of mysql_insert_id function

mysql_insert_id(connection)

Parameters in mysql_insert_id function

It has only one parameter:

Parameter Description
connection It specifies MySQL connection.

Example of mysql_insert_id function

<?php

$con=mysql_connect("localhost","gupta","sharad");

if(!$con)

{

die("Could not connect:".mysql_error());

}

mysql_select_db("Mcn_Solution",$con);

$res=mysql_query("insert into Emp values('Tony','Blair','110')");

echo "Id of last inserted record is:" .mysql_insert_id();

mysql_close($con);

?>


Output:

mysql-insert-id-php.jpg

You may also want to read these related articles :
here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.