【问题标题】:Fixing: mysql_fetch_assoc() expects parameter 1 to be resource, string given [duplicate]修复:mysql_fetch_assoc() 期望参数 1 是资源,给定字符串 [重复]
【发布时间】:2015-02-09 23:11:58
【问题描述】:

直接进入主题..

这是错误:

警告:mysql_fetch_assoc() 期望参数 1 是资源,字符串在第 55 行的 /home/u861005887/public_html/blog/rating/index.php 中给出

这是错误的屏幕截图:

被评为 # 次的内容无效。
评级为 # 无效。

我该如何解决这个问题?

【问题讨论】:

  • 在不查看代码的情况下调试代码……很难。我敢打赌,您将查询传递给mysql_fetch_assoc,而不是运行查询并执行结果。您正在使用an obsolete database API,无论如何都应该使用modern replacement
  • @Clive — 字符串,不是布尔值。
  • 公平点@Quentin,这个就行了:stackoverflow.com/questions/4901728/…
  • 我的猜测是您忘记了存储结果集的变量名称前面的$

标签: php


【解决方案1】:

错误:“expects parameter 1 to be resource, string given in”解释了你将字符串传递给函数。例如,mysql_fetch_assoc 必须接收到 mysql_query 请求的结果,并且 mysql_result 必须首先成功。

另外,mysql_已经过时了,你应该使用PDO,强烈推荐。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-21
    • 2012-02-07
    • 2011-06-21
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多