MYSQL错误:警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值 [英] MYSQL Error : Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given
本文介绍了MYSQL错误:警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的SQL查询有什么问题吗?我总是会收到此错误
Is there anything wrong with my sql query? I always get this error
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given
<?php
include("connection.php");
$mysqli->query("SET NAMES 'utf8'");
$filter = "All";
if ($filter == "All"){
$sql="SELECT * FROM city ";
}else if($filter == "Alphabetically"){
$sql="SELECT * FROM city order by cityName ASC";
}else if ($filter == "Region"){
$sql="SELECT * FROM city order by region";
}else{
echo "Error sql";
}
$result=$mysqli->query($sql);
while($e=mysqli_fetch_assoc($result)){
$output[]=$e;
}
print(json_encode($output));
$mysqli->close();
推荐答案
我假设您正在使用mysqli中的OO机制连接到数据库,因为这是几乎所有mysqli命令所使用的
I assume you are connecting to the database using the OO mechanism in mysqli as that is what you are using for almost all your mysqli commands
但是这里
while($e=mysqli_fetch_assoc($result)){
您已更改为过程函数调用.
you have changed to the proceedural function calls.
代替
while($e = $result->fetch_assoc()){
这篇关于MYSQL错误:警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文