有结果集的mysqli函数获取行数和列数

<?php
    $mysqli=new mysqli("localhost", "root", "123456", "xsphpdb");

    if(mysqli_connect_errno()){
        echo "错误:".mysqli_connect_error();
        exit;
    }

    //执行select语句,返回来的就是结果集(对象)
    
    $sql="select id,name from shops where id <50";

    $result=$mysqli->query($sql);

    $rows=$result->num_rows;
    $cols=$result->field_count;

    echo "表中{$rows}行,{$cols}列<br>";
    


    $mysqli->close();

 

posted @ 2015-12-04 15:43  对数螺旋线  阅读(1890)  评论(0编辑  收藏  举报