mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源 [英] mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

查看:59
本文介绍了mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
警告:mysql_fetch_array():提供的参数不是有效的MySQL结果

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

我真的很坚持这个,我正在得到这个错误: mysql_fetch_assoc():提供的参数不是文件名"中的有效MySQL结果资源

I' really stuck on this , I'm gettiing this error: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in "filename"

这是代码:

 $sql = "SELECT * FROM $tbl_name WHERE....
 $result=mysql_query($sql);
 $row = mysql_fetch_assoc($result);

奇怪的是,我之前使用了完全相同的代码,而且效果很好

The wierd thing is that I've used the exact same code before and it worked fine

任何想法?

推荐答案

这意味着查询失败.通常,这是SQL语法错误.要找出答案,只需在_fetch_assoc行之前插入以下内容:

That means the query failed. Usually it's a SQL syntax error. To find out, just insert this right before the _fetch_assoc line:

print mysql_error();

为防止出现此错误消息,请像下面这样构建代码,以预先检查$ result:

To prevent the error message, structure your code like this to check the $result beforehand:

$sql = "SELECT * FROM $tbl_name WHERE....";

if ($result = mysql_query($sql)) {
    $row = mysql_fetch_assoc($result);         
}
else print mysql_error();

这篇关于mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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