到目前为止,我一直在yii2
中使用SQL查询,该查询在本地运行良好,但只要我将其部署到服务器就显示
我已经尝试将其更改为yii查询,因为它是在
下面的正确实现$query = $connection->createCommand("SELECT a.name_of_flight, a.time_of_flight, (a.no_of_passenger - b.cnt) as avail, a.no_of_passenger FROM flight_schedule a LEFT JOIN (SELECT flight_time, COUNT(id) AS cnt FROM book_eticket WHERE flight_date='$date' AND company_name = '$comp_name' GROUP BY flight_time) b ON a.id = b.flight_time")->queryAll();
到
$query = (new \yii\db\Query());
$query
->select('a.name_of_flight, a.time_of_flight, (a.no_of_passenger - b.cnt) as avail, a.no_of_passenger')
->from('flight_schedule a')
->leftJoin('flight_time', ('COUNT(id) AS cnt FROM book_eticket'))
->where(array('and', 'flight_date=2016-6-29', 'company_name = Team5'))
->groupBy(['flight_time b','ON a.id = b.flight_time']);
$command = $query->createCommand();
$query = $command->queryAll();
但是我收到了错误:
有人可以帮我找出问题吗?提前致谢
答案 0 :(得分:1)
第一个屏幕说明了访问问题。第二 - 像 date 和 team 这样的操作数不是字符串。那是错的。你能引用它们吗?