zoukankan      html  css  js  c++  java
  • PHP操作Mysql数据库查询数据实例

    需求

    1. PHP连接数据库
    2. 查询遍历所有数据

    PHP连接数据库

    //config.php文件内容
    $database = "xx";
    $dataname = "root";
    $datapasswd = "xxx";
    $datalocal = "localhost:3306";
    //$dataport = "3306";
    $con = mysqli_connect($datalocal,$dataname,$datapasswd,$database);
    if(!$con){
        echo "数据库连接异常";
    }
    //设置查询数据库编码
    mysqli_query($con,'set names utf8');
    

    查询遍历所有数据

    <?php
    //连接数据库
    include './inc/config.php';
    //查询数据库
    $query = 'select * from user';
    $result1 = mysqli_query($con,$query);
    
    
    //函数返回结果集中行的数量
    if(mysqli_num_rows($result1)>0){
    //mysqli_fetch_array以数组的形式返回,关联数组
    while($row = mysqli_fetch_array($result1)){
           
        echo     
     "<center>
    <table>
     <tr>
       <th>账号</th>
       <th>密码</th>
     </tr>
     <tr>
        <td>".$row['id']."</td>
       <td>".$row['name']."</td>
       <td>".$row['password']. "</td>
     </tr>
    </table>
    </center>";
     }      
    }
    //关闭数据库
     mysqli_close($con);
     ?>
    

  • 相关阅读:
    缓存
    Java缓存
    数据库事务
    spring 事务管理
    MySQL错误解决10038
    mysql存储过程
    ECS修改默认端口22及限制root登录
    xunsearch安装配置
    https和http共存的nginx配置
    ECS 安装redis 及安装PHPredis的扩展
  • 原文地址:https://www.cnblogs.com/QinTO/p/11865375.html
Copyright © 2011-2022 走看看