• 数据访问


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>


    <table width="100%" border="1" cellpadding="0" cellspacing="0">

    <tr>
    <td>代号</td>
    <td>姓名</td>
    <td>性别</td>
    <td>民族</td>
    <td>生日</td>
    </tr>

    <?php

    //造一个mysqli对象,造连接对象
    $db = new MySQLi("localhost","root","123","mydb");

    //准备一条SQL语句
    $sql = "select * from info";

    //执行SQL语句,如果是查询语句,成功返回结果集对象
    $reslut = $db->query($sql);

    //判断返回是否执行成功
    if($reslut)
    {
    while($attr = $reslut->fetch_row())
    {
    echo "<tr>
    <td>{$attr[0]}</td>
    <td>{$attr[1]}</td>
    <td>{$attr[2]}</td>
    <td>{$attr[3]}</td>
    <td>{$attr[4]}</td>
    </tr>";
    }

    }



    ?>

    </table>






    </body>
    </html>







    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>

    <?php

    //造连接对象
    $db = new MySQLi("localhost","root","123","mydb");

    //准备SQL语句
    $sql = "delete from info where code='p004'";

    //执行SQL语句
    $r = $db->query($sql);

    if($r)
    {
    echo "执行成功";
    }
    else
    {
    echo "执行失败";
    }


    ?>

    </body>
    </html>







    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>



    <?php
    $db = new MySQLi("localhost","root","123","mydb");
    $sql = "select * from nation";
    $result = $db->query($sql);

    echo "<select>";

    if($result)
    {
    while($attr = $result->fetch_row())
    {
    echo "<option value='{$attr[0]}'>{$attr[1]}</option>";
    }
    }

    echo "</select>";

    ?>





    </body>
    </html>
  • 相关阅读:
    LeetCode 3-Longest Substring Without Repeating Characters
    LeetCode 2-Add Two Numbers
    LeeCode 1-Two Sum
    Python中Lambda, filter, reduce and map 的区别
    解决Eclipse10配置Pydev不成功的问题
    Pythonxy下载链接
    546C. Soldier and Cards
    欧拉工程第58题:Spiral primes
    欧拉工程第57题:Square root convergents
    Linux编辑器vim键盘详解
  • 原文地址:https://www.cnblogs.com/jc535201285/p/6434048.html
Copyright © 2020-2023  润新知