Mysql:警告:mysql_fetch_array() 期望参数 1 为资源 [英] Mysql: Warning: mysql_fetch_array() expects parameter 1 to be resource

查看:60
本文介绍了Mysql:警告:mysql_fetch_array() 期望参数 1 为资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前在 mysql 中创建了一个数据库,现在我试图在表中列出它的所有值,但出现以下错误 警告:mysql_fetch_array() 期望参数 1 为资源,布尔值上线:while($row=mysql_fetch_array($result))

I earlier made a database in mysql and now i am trying to list all the values from it in a table, but I get the following error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean on line: while ($row=mysql_fetch_array($result))

这是我的代码:

$con=mysql_connect("localhost","root","");
if (!$con) {
    die("Error: " . mysql_error);
}

mysql_select_db("my_db",$con);

$result = mysql_query("SELECT * FROM Users");

echo "<table border='1'>
<tr>
<th>Username</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Email adress</th>
</tr>";

while($row=mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['username'] . "</td>";
    echo "<td>" . $row['firstname'] . "</td>";
    echo "<td>" . $row['lastname'] . "</td>";
    echo "<td>" . $row['age'] . "</td>";
    echo "<td>" . $row['emailadress'] . "</td>";
    echo"</tr>";
}
echo "</table>";

mysql_close($con);

我阅读了其他类似的问题,但没有得到答案.

I read other similar question but diden't get an answer.

推荐答案

您的代码不会评估来自 MySQL 的有关选择数据库或运行查询的响应.该错误表明您的查询未成功(因此 mysql_query 返回 FALSE) - 这意味着上述一项或两项无效.

Your code doesn't evaluate the response from MySQL about selecting the database or running your query. The error indicates that your query didn't succeed (hence mysql_query returns FALSE) - which means one or both of the above didn't work.

选择数据库并使用 die(mysql_error()) 时测试错误;了解这些调用失败的原因.

Test for errors when you select the database and use die(mysql_error()); to see why these calls are failing.

这篇关于Mysql:警告:mysql_fetch_array() 期望参数 1 为资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆