douyuanqia665858 2012-08-02 02:43
浏览 53
已采纳

MySQL错误:mysql_fetch_array期望参数1是资源[重复]

Possible Duplicate:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error

I recently got a work from a client, where I have to change the depreciated php old code to new one. In that code I came across mysql_db_query which I converted into mysql_query but the error was given

mysql_fetch_array expects parameter 1 to be resource, boolean given

//the old code was like:

$result = mysql_db_query($mysql_db,"SELECT Hierarchy FROM MenuSystem WHERE LENGTH(Hierarchy) >= 2 AND LOCATE(" . $_SESSION['AccessLevel'] . ",AccessLevels) <> 0;");

//and my new code is :

$result = mysql_query("SELECT Hierarchy FROM MenuSystem WHERE LENGTH(Hierarchy) >= 2 AND LOCATE(" . $_SESSION['AccessLevel'] . ",AccessLevels) <> 0");

please tell me the problem

it refers to line number 11 where is the end bracket of while loop

while ($row = mysql_fetch_array($result)) {
    $ConcatHierarchy .= $row["Hierarchy"];
}
  • 写回答

2条回答 默认 最新

  • doufang8282 2012-08-02 02:51
    关注

    I can't see that the sole code will cause error. However, if you want to use $result as an array, that may rise a problem as we need to check it first. If query fails it will return a FALSE rather than a resource i.e., an array.

    (I mean you use the resource later as an array actually. But yes $result is either a FALSE or a resrouce which can be used by calling mysql_fetch_array(). thanks for your comment)

    Actually you can check other posts such as: mysql_fetch_array() expects parameter 1 to be resource problem

    fyi, as suggested by the manual, ppl may prefer PDO now: Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊