如何修复此查询

y1aodyip  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(306)

下面的方法总是返回一个空数组作为从mysql返回数据的查询。
如果我这样写查询就行了 SELECT * FROM menu 此问题出现在aws ec2服务器上,并且与在本地主机上正常工作的方法相同
这个 SELECT * FROM menu WHERE type = ? ORDER BY likes DESC 在通过添加location列更新表之前,查询工作正常,现在没有人工作
我试着从头开始重新设计table

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;
}
iugsix8n

iugsix8n1#

我想你的问题是关于“菜单”表的用户权限。检查用户权限

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 根据需要。

相关问题