PHP mysql_insert_id() a baya

tafsiwa da amfani

a baya mysql_insert_id() na kai kai ID a hoto a hoto INSERT.

idana kuma ana fadi a hoto kai kama ID AUTO_INCREMENT a hoto, ka fi 0 na a baya mysql_insert_id().

Syntax

mysql_insert_id(connection)
Parameter Description
connection Optional. Specifies the MySQL connection. If not specified, it uses the last connection.

Description

mysql_insert_id() returns the given connection The AUTO_INCREMENT ID number generated in the previous step INSERT query. If not specified connection If not specified, it uses the last opened connection.

Tips and comments

Note:If you need to save this value for later use, make sure to call mysql_insert_id() immediately after the query that generates the value.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("test_db",$con);
$sql = "INSERT INTO person VALUES ('Carter','Thomas','Beijing')";
$result = mysql_query($sql,$con);
echo "ID of last inserted record is: " . mysql_insert_id();;
mysql_close($con);
?>

Output similar to:

ID of last inserted record is: 5