我正在为一个项目运行一个非常基本的脚本--一个工作,我有一个有大量联系人的数据库,我需要这个脚本来查看结果并显示一个基本的表,我让脚本工作了,但是突然之间,它没有任何数据库信息--这是我正在使用的代码:
<?php
$con=mysqli_connect("localhost","root","password","main");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM users");
echo "<table border='1'>".
"<tr><th>ID</th>".
"<th>Rating</th>".
"<th>Name</th>".
"<th>Discipline</th>".
"<th>Rate</th>".
"<th>Location</th>".
"<th>Number</th>".
"<th>Email</th>".
"</tr>";
while($row = mysqli_fetch_array($result));
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Rating'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Discipline'] . "</td>";
echo "<td>" . $row['Rate'] . "</td>";
echo "<td>" . $row['Location'] . "</td>";
echo "<td>" . $row['Number'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>如果有人把我引向正确的方向,那就太好了,谢谢。
编辑:发布后,我复制了一段我正在调试的旧代码,但没有包含fetch_array。
发布于 2015-12-16 10:00:56
我在你的代码中看到了很小的错误,
添加分号时循环无效。
从你的代码。
while($row = mysqli_fetch_array($result))谢谢阿米特
发布于 2015-12-16 09:59:14
$result = mysqli_query($con,"SELECT * FROM users");在上面,您告诉它使用到数据库的连接,然后从数据库中的一个表中选择一些数据,但是,如果查询失败,您还没有告诉它该怎么做,请尝试如下:
$result = mysqli_query($con,"SELECT * FROM users") or die(mysqli_error($con));发布于 2015-12-16 10:00:17
若要帮助在开发模式下调试,请执行以下操作:
显示php错误:How do I get PHP errors to display?
让Mysqli抛出异常:STRICT?
您能否与另一个客户端连接到mysql数据库并在那里运行查询:
$ mysql -uusername -p databasename
mysql> SELECT * FROM users;https://stackoverflow.com/questions/34308421
复制相似问题