<?php
header('Content-Type:text/html;Charset=utf-8');
$db = new mysqli();
$db->connect('localhost','root',12345,'test');
$sql='select * from category';
$query=$db->query($sql);
while($rs=mysqli_fetch_array($query)){
$result[]=$rs;
}
$i=0;
print_r($result);
echo '<hr>';
foreach($result as $key=>$value){
$i+=1;
if($i%2==0){
echo $key.' ';
echo $value.'<hr>';
}
}
$query->free();
$db->close();
PHP mysqli遍历表字段名和值
最新推荐文章于 2023-09-17 00:40:50 发布
本文展示了一个使用PHP连接MySQL数据库并从category表中获取所有记录的例子。通过实例介绍了如何建立数据库连接、执行SQL查询及处理结果集。

674

被折叠的 条评论
为什么被折叠?



