2024年09月10日 建站教程
如何利用php语法实现查询mysql并返回数组,下面web建站小编给大家简单介绍一下!
php语法链接mysql数据库
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检查连接是否成功 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } ?>
php语法查询mysql数据库返回数组
<?php $sql = "SELECT * FROM `表`"; $result = $conn->query($sql); if ($result->num_rows > 0) { // 将查询结果存储到数组中 $data = array(); while($row = $result->fetch_assoc()) { $data[] = $row; } } else { echo "0 结果"; } ?>
本文链接:http://so.lmcjl.com/news/12689/