码迷,mamicode.com
首页 > 编程语言 > 详细

php基本语言总结

时间:2020-07-11 12:40:39      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:span   fetch   关联   基本   失败   mysql   png   name   ima   

1,

mysqli_fetch_row记录集获取

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

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

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

<?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 "<br/>"

}

?>

技术图片

 

 

 

<?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<$cols;$i++)

        {

             echo $row[$i];

             if($i<$cols-1)echo ",";

        }

        echo "<br/>";

    }

?>

技术图片

 

 

 2

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 "<br/>";

    }

?>

技术图片

 

 

<?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 "<br/>";

}

?>

技术图片

 

 3

mysqli_fetch_array记录集获取

 

技术图片

 

 

while($row=mysqli_fetch_array($result))

{

    $cols=count($row)/2;

    for($i=0;$i<$cols;$i++)

    {

         echo $row[$i];

         if($i<$cols-1)echo ",";

    }

    echo "<br/>";

}

?>

技术图片

 

 技术图片

 

 

<?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 "<table border=1>";

echo "<tr><td>学号</td><td>姓名</td><td>性别</td><td>出生日期</td><td>电话号码</td><td>邮箱</td></tr>";

while($row=mysqli_fetch_array($result))

    {

    echo "<tr>";

        foreach($row as $k=>$v)

        {

            if(!is_numeric($k)){

            echo "<td>$v</td>";

            

            }

        }

    echo "</tr>";

  


    }

echo "</table>";

?>

技术图片

 

php基本语言总结

标签:span   fetch   关联   基本   失败   mysql   png   name   ima   

原文地址:https://www.cnblogs.com/520520520zl/p/13282843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!