php基本语言总结

Posted 520520520zl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php基本语言总结相关的知识,希望对你有一定的参考价值。

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基本语言总结的主要内容,如果未能解决你的问题,请参考以下文章

MorkDown 常用语法总结

非常实用的33个PHP代码实例

Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结

10个超级有用必须收藏的PHP代码样例

VS中添加自定义代码片段——偷懒小技巧

JavaSE 方法的使用