php的mysqli_insert_id() 函数

mysqli_insert_id() 函数的作用是返回最近一条insert语句自动生成的 ID

用法:

<?php
//  https://www.51dev.com
//  IT开发社区
$con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno($con)){
  echo "连接数据库错误" . mysqli_connect_error();
}

mysqli_query($con,"INSERT INTO table_1(name) VALUES('www.51dev.com')");

echo "id: " . mysqli_insert_id($con); 

mysqli_close($con);
?>

 

你可能感兴趣的