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>"; }
}>#
php修改数据库内容//关闭数据库
mysqli_close($con); >

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论