您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
使用PHP中mysqli扩展处理结果集
发布时间:2015-11-25 08:05:22编辑:雪饮阅读()
<?php
$mysqli=new MySQLi("localhost","root","root","test2");
if(mysqli_connect_errno()){
echo "数据库连接失败:".mysqli_connect_error();
$mysqli=null;
exit;
}
echo "数据库连接成功";
$sql="select * from biao4";
$res=$mysqli->query($sql);
//移动结果集中指针位置(纵向)
$res->data_seek(3);
//移动结果集中字段指针位置(横向)
$res->field_seek(1);
echo "<table>";
echo "<tr>";
//fetch_field()字段信息
while($fieds=$res->fetch_field()){
echo "<th>".$fieds->name."</th>";
}
echo "</tr>";
//fetch_assoc仅仅是关联数组
while($row=$res->fetch_assoc()){
echo "<tr>";
foreach($row as $col){
echo "<td>".$col."</td>";
}
echo "</tr>";
}
echo "</table>";
//释放结果集
$res->free();
$mysqli->close();
?>
关键字词:php,mysqli,结果集