下面的方法总是返回一个空数组,因为查询是从MySQL返回数据。
如果我像这样写SELECT * FROM menu
此问题出现在AWS EC2服务器上,并且该方法在我的本地主机上正常工作
SELECT * FROM menu WHERE type = ? ORDER BY likes DESC
查询在添加位置列以更新表格之前运行良好,现在没有人可以使用我试图从头开始重新创建表
function getMenu($type)
{
$stmt = $this->con->prepare("SELECT * FROM menu WHERE type = ? ORDER BY likes DESC");
$stmt->bind_param("s", $type);
$stmt->execute();
$stmt->bind_result($id, $dish_name, $dish_disc, $type, $image, $location, $likes, $price);
}
function getMenuByLocation($type, $location){
$common = 'common';
$stmt = $this->con->prepare("SELECT * FROM menu WHERE type = ? AND
location IN (?, 'common') ORDER BY likes DESC");
$stmt->bind_result($id, $dish_name, $dish_disc, $type, $image,
$location, $likes, $price);
while ($stmt->fetch()) {
$temp = array();
$temp['dId'] = $id;
$temp['dishName'] = $dish_name;
$temp['dishDisc'] = $dish_disc;
$temp['type'] = $type;
$temp['imageUrl'] = $image;
$temp['location'] = $location;
$temp['likes'] = $likes;
$temp['price'] = $price;
array_push($dish, $temp);
}
return $dish;
}
答案 0 :(得分:0)
我认为您的问题与表'menu'上的用户权限有关。检查用户权限
SHOW GRANTS FOR 'user'@'domain';
在连接字符串中将'user'@'domain'更改为您的用户名。
尝试
GRANT ALL ON your_db_name.menu TO 'user'@'domain';
请注意,此查询应由具有足够特权的用户执行。
根据需要参考https://dev.mysql.com/doc/refman/5.5/en/privilege-system.html。