获取自动增长IDmysqli函数

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语句有误
"; echo "ERROR:".$mysqli->errno."|".$mysqli->error; exit; } if($mysqli->affected_rows > 0){ echo "有行数被影响
"; } echo "最后自动增长的ID:".$mysqli->insert_id; $mysqli->close();

 

你可能感兴趣的:(获取自动增长IDmysqli函数)