欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP mysql_insert_id() 函數(shù)

定義和用法

mysql_insert_id() 函數(shù)返回上一步 INSERT 操作產(chǎn)生的 ID。

如果上一查詢(xún)沒(méi)有產(chǎn)生 AUTO_INCREMENT 的 ID,則 mysql_insert_id() 返回 0。

語(yǔ)法

mysql_insert_id(connection)
參數(shù) 描述
connection 可選。規(guī)定 MySQL 連接。如果未規(guī)定,則使用上一個(gè)連接。

說(shuō)明

mysql_insert_id() 返回給定的 connection 中上一步 INSERT 查詢(xún)中產(chǎn)生的 AUTO_INCREMENT 的 ID 號(hào)。如果沒(méi)有指定 connection ,則使用上一個(gè)打開(kāi)的連接。

提示和注釋

注釋?zhuān)?/span>如果需要保存該值以后使用,要確保在產(chǎn)生了值的查詢(xún)之后立即調(diào)用 mysql_insert_id()。

例子

<?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);
?>

輸出類(lèi)似:

ID of last inserted record is: 5