<span style="font-size:14px;">header("content-type:text/html;charset=utf-8");
$host="localhost";
$user="root";
$password="root";
$port=3306;
$db="baixing";
//顺序为$host,$user,$password,$db,$port
$conn=new mysqli($host,$user,$password,$db,$port);
if(!$conn){
die("error:".$conn->connect_error);
}
$result=$conn->query("select * from user");
/</span><span style="font-size:18px;color:#ff0000;">fetch_all()的用法</span><span style="font-size:14px;">///fetch_all()所有查询的数据放在一个数组里
$myarr=$result->fetch_all();
foreach($myarr as $item){
echo "id=".$item[0].";user=".$item[1].";pass=".$item[2];
}
</span><span style="font-size:18px;color:#ff0000;">fetch_object()的用法</span><span style="font-size:14px;">/fetch_object()获取一个对象
while($row =$result->fetch_object()){
echo "id=".$row->Id.";user=".$row->username.";pass=".$row->password."<br/>";
}
/</span><span style="font-size:24px;color:#ff0000;">fetch_array()的用法</span><span style="font-size:14px;">fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组
while($row=$result->fetch_array()){//mysql_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组
echo "id:".$row["Id"].";username=".$row["username"].";password=".$row["password"]."<br/>";
echo "id:".$row[0].";username=".$row[1].";password=".$row[2]."<br/>";
}
$conn->close();</span>
php连接数据库后fetch_object()、fetch_all()、fetch_array()的用法
最新推荐文章于 2023-10-02 02:12:13 发布