php基本语言总结
2021-04-21 00:27
标签:span fetch 关联 基本 失败 mysql png name ima 1, mysqli_fetch_row();//用来将查询结果的一行保存至索引数组; mysqli_fetch_assoc();//用来将查询结果的一行保存至关联数组; mysqli_fetch_array();//前2者的结合。 2 3 php基本语言总结 标签:span fetch 关联 基本 失败 mysql png name ima 原文地址:https://www.cnblogs.com/520520520zl/p/13282843.htmlmysqli_fetch_row记录集获取
php
$conn=mysqli_connect("localhost","root","111111","mydb") or die("数据库连接失败");
mysqli_query($conn,‘set names utf8‘);
$sql="select * from student";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
while($row=mysqli_fetch_row($result))
{
print_r($row);
}
?>
php
$conn=mysqli_connect("localhost","root","111111","mydb") or die("数据库连接失败");
mysqli_query($conn,‘set names utf8‘);
$sql="select * from student";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
while($row=mysqli_fetch_row($result))
{
echo "$row[0],$row[1],$row[2],$row[3],$row[4],$row[5]"
echo "
"
}
?>php
$conn=mysqli_connect("localhost","root","111111","mydb") or die("数据库连接失败");
mysqli_query($conn,‘set names utf8‘);
$sql="select * from student";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
while($row=mysqli_fetch_row($result))
{
$cols=count($row);
for($i=0;$i)
{
echo $row[$i];
if($i1)echo ",";
}
echo "
";
}
?>mysqli_fetch_assoc记录集获取
php
$conn=mysqli_connect("localhost","root","111111","mydb") or die("数据库连接失败");
mysqli_query($conn,‘set names utf8‘);
$sql="select * from student";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
while($row=mysqli_fetch_assoc($result))
{
echo "row[stu_no],$row[stu_name],$row[sex],$row[birthdate],$row[telephone],$row[email]";
echo "
";
}
?>php
$conn=mysqli_connect("localhost","root","111111","mydb") or die("数据库连接失败");
mysqli_query($conn,‘set names utf8‘);
$sql="select * from student";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
while($row=mysqli_fetch_assoc($result))
{
foreach($row as $k=>$v)
{
echo $v;
if($k!="email")echo ",";
}
echo "
";
}
?>mysqli_fetch_array记录集获取
while($row=mysqli_fetch_array($result))
{
$cols=count($row)/2;
for($i=0;$i)
{
echo $row[$i];
if($i1)echo ",";
}
echo "
";
}
?>php
$conn=mysqli_connect("localhost","root","111111","mydb") or die("数据库连接失败");
mysqli_query($conn,‘set names utf8‘);
$sql="select * from student";
$result=mysqli_query($conn,$sql)or die("数据查询失败");
echo "
";
echo "
";
?>
";
while($row=mysqli_fetch_array($result))
{
echo "学号
姓名
性别
出生日期
电话号码
邮箱
";
foreach($row as $k=>$v)
{
if(!is_numeric($k)){
echo " ";
}
echo "
$v
";
}
}
echo "
下一篇:稀疏数组