mysqli_insert_id()
跟在数据库插入动作后面,返回刚插入数据库的auto_increment字段
例:
$conn = mysqli_connect(localhost,root,cimg123);
mysqli_select_db($conn,test);
$sql = "insert test (username) values ('cimg')";
$result = mysqli_query($conn,$sql);
$id = mysqli_insert_id($conn);
echo $id;
mysqli_close($conn);
?>
或者
$conn = new mysqli(localhost,root,cimg123,test);
$sql = "insert test (username) values ('cimg')";
$result = $conn->query($sql);
$id = mysqli_insert_id($conn);
echo $id;
$conn->close();
?>
阅读(3833) | 评论(1) | 转发(0) |