2021.4.13

mysqli_fetch_row();//用来将查询结果的一行保存至索引数组;

mysqli_fetch_assoc();//用来将查询结果的一行保存至关联数组;

mysqli_fetch_array();//前2者的结合。

 

1.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>row</title>
</head>
<body>
<?php
$conn=mysqli_connect("localhost","root","aliez0.0.","mydate1");
if(!$conn){
die("数据库连接失败");
}
echo "数据库连接成功";
echo "<br/>";
mysqli_query($conn,'set names utf8');

$sql="select * from student2";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
$row=mysqli_fetch_row($result);
print_r($row);
echo "<br/>";
$row=mysqli_fetch_row($result);
print_r($row);
?>
</body>
</html>

2.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>assoc</title>
</head>
<body>
<?php
$conn=mysqli_connect("localhost","root","aliez0.0.","mydate1");
if(!$conn){
die("数据库连接失败");
}
echo "数据库连接成功";
echo "<br/>";
mysqli_query($conn,'set names utf8');

$sql="select * from student2";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
$row=mysqli_fetch_assoc($result);
print_r($row);
echo "<br/>";
$row=mysqli_fetch_assoc($result);
print_r($row);
?>
</body>
</html>

3.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>array</title>
</head>
<body>
<?php
$conn=mysqli_connect("localhost","root","aliez0.0.","mydate1");
if(!$conn){
die("数据库连接失败");
}
echo "数据库连接成功";
echo "<br/>";
mysqli_query($conn,'set names utf8');

$sql="select * from student2";
$result=mysqli_query($conn,$sql)or die("数据查询失败");

$row=mysqli_fetch_array($result);

print_r($row);

echo "<br/>";

$row=mysqli_fetch_array($result);

print_r($row);
?>
</body>
</html>

 

posted @ 2021-04-14 00:00  鯨落  阅读(63)  评论(0编辑  收藏  举报