mysqli:循环数据显示到页面
连接数据库smarty_fenye 数据表tbl_product
mysqli-----连接对象
mysqli_result----select结果集对象
mysqli_stmt----预处理对象
一:连接数据库mysqli
$mysqli=new mysqli(“localhost”,”root”,”123”,”smarty_fenye”);
二:发送多条语句
$sql=”set names gbk;select * from tbl_product;select name price tbl_product”;
三:循环显示
if($mysqli->multi_query($sql)){
do{
if($result=$mysqli->store_result()){
while($row=$result->fetch_row()){
foreach($row as $value){
echo $value."<br>";
}
}
echo "<br>";
//返回总行数
echo "总行数:".$result->num_rows;
echo "<br>";
echo "总列数:".$result->field_count;
echo "<br>";
echo $result->current_field."当前列";
echo "<br>";
@ $result->field_seek(1);
echo $result->current_field."当前列";
echo "<br>";
$a=$result->fetch_field();
echo "名称1:".$a->name;
echo "<br>";
@ $result->field_seek(2);
echo $result->current_field."当前列";
echo "<br>";
$b=$result->fetch_field();
echo "名称2:".$b->name;
echo "<br>";
}
}while($mysqli->next_result());
}