Home  >  Article  >  Backend Development  >  php expects parameter 1 to be resource, array given 错误_PHP

php expects parameter 1 to be resource, array given 错误_PHP

WBOY
WBOYOriginal
2016-06-01 12:17:07891browse

如果你使用的是封装好的类
例如
function fetch_array($query, $result_type = MYSQL_ASSOC) {
return mysql_fetch_array($query, $result_type);
}
[/code]
会报这个错误
这是应为,你传递的$query是布尔值,而mysql_fetch_array 里面的参数需要的是资源类型,这是,你的程序会判定你传递的参数错误,
我们可以
复制代码 代码如下:
function fetch_array($query, $result_type = MYSQL_ASSOC) {
return @mysql_fetch_array($query, $result_type);
}

在前面使用@来禁止错误提示,或者
试用判读语句来执行这个语句,
复制代码 代码如下:
if(这个参数)
{
执行
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn