获取mysqli函数的值和字段名

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

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

    //执行select语句,返回来的就是结果集(对象)
    
    $sql="select id cid, name shopname, price shopprice, num shopnum, desn shopdesn from shops";

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

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

    echo "表中{$rows}行,{$cols}列
"; //记录信息 /* $result->fetch_row() ---- mysql_fetch_row() 索引数组 * $result->fetch_assoc() --- mysql_fetch_assoc() 关联数组(下标就是列名) * $result->fetch_array() ---- mysql_fetch_array() 两个数组都返回(MYSQLI_ASSOC, MYSQLI_NUM,MYSQLI_BOTH(default)) * $result->fetch_object() --- mysql_fetch_object() * * 每次执行一次,就会从结果集中取出当前一条记录(当前记录就是第一个行,可以使用data_seek(5)) * * 指针指向下一行,下次再取时,就会取出下一行,当结果集中没有记录时,则返回false * */ echo ''; echo ''; // $result->field_seek(2);while($field=$result->fetch_field()){ echo ''; } echo ''; // $result->data_seek(50);while($row=$result->fetch_assoc()){ echo ''; foreach($rowas$col){ echo ''; } echo ''; } echo '
'.$result->current_field.'_['.$field->orgname.']'.$field->name.'('.$field->max_length.')
'.$col.'
'; $result->free(); $mysqli->close();

 

你可能感兴趣的:(获取mysqli函数的值和字段名)