警告错误mysqli_fetch_array()/mysqli_fetch_assoc()/mysqli_fetch_row() expects parameter 1 to be resource boolean given的解决方法

时间:2017-10-29
在php mysql编程中,我们经常会遇到这要的错误mysqli_fetch_array expects parameter 1 to be resource boolean given,这个错误的根本原因是mysqli_fetch_array接受的参数是boolean,而不是resource类型,本文章向大家介绍如何解决这种类型的错误,需要的朋友可以参考一下。

今天在编写php mysql数据库编程的时候,遇到了mysql_fetch_row() expects parameter 1 to be resource, boolean given 的错误。后来仔细检查了一下代码,问题得到解决。将解决方法记录下来给大家分享一下。

我的代码如下:

<?
//error message (not found message)
$XX = "No Record Found";
mysql_select_db("india3arts") or die( "Unable to select database");
?>
<?
//error message (not found message)
$XX = "No Record Found";
$result1 = msql_query ("select * FROM items where ".$metode." like '%".$search."%' limit 0,     1095 ");
while ($row = mysql_fetch_array($result1))
{
$variable1=$row["itemDesc"];
$variable2=$row["itemName"];
$variable3=$row["itemPrice"];
print ("this is for $row["itemDesc"];, and this print the variable2 end so on...");

}
//below this is the function for no record!!
if (!$variable1)
{
print ("$XX");
}
//end
?>

上面代码出现mysql_fetch_row() expects parameter 1 to be resource, boolean given 的错误,原因是mysql_query这里出错,传入的sql字符串无法正确执行,导致$result1为false。

总结

当你看到这个的警告的时候 肯定是因为你的SQL语句没有执行成功,仔细检查一下数据库配置然后打印出所执行的SQL语句,很可能是不小心打错的小错误。