获取自动增长IDmysqli函数

时间:2021-11-17 01:16:11
<?php
$mysqli=@new mysqli("localhost", "root", "123456", "xsphpdb"); if(mysqli_connect_errno()){
echo "连接数据库失败:".mysqli_connect_error();
$mysqli=null;
exit;
} //select语句(结果集), 非select语句,会影响行数 $sql="insert into shops(name,price,num,desn) values('hello','34.56','22','good123')";
//$sql="delete from shops where id > '80'"; $result=$mysqli->query($sql); if(!$result){
echo "SQL语句有误<br>";
echo "ERROR:".$mysqli->errno."|".$mysqli->error;
exit;
} if($mysqli->affected_rows > 0){
echo "有行数被影响<br>";
} echo "最后自动增长的ID:".$mysqli->insert_id; $mysqli->close();