判断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 @ 2015-12-04 15:27  对数螺旋线  阅读(422)  评论(0编辑  收藏  举报