判断mysqli函数里的sql语句是否有错和影响行数

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

    $result=$mysqli->query($sql);
    
    if(!$result){
        echo "SQL语句有误<br>";
        echo "ERROR:".$mysqli->errno."|".$mysqli->error;
        exit;    
    }

    echo $mysqli->affected_rows;

    $mysqli->close();

 

posted @ 2019-10-30 20:24  汉学  阅读(151)  评论(0编辑  收藏  举报