【发布时间】:2018-02-22 06:12:28
【问题描述】:
我正在使用CakePHP 3.x+
我必须在页面上显示一个图表,因此想为此构建脚本。
我必须按月选择当年的记录数。
这是我尝试过的。
$graph = $this->GenerateVideos->find()
->select('COUNT(id)', 'MONTH(created)')
->where(['YEAR(created)' => date('Y')])
->group(['MONTH(created)']);
生成类似的sql
'sql' => 'SELECT GenerateVideos.COUNT(id) AS GenerateVideos__COUNT(`id`) FROM generate_videos GenerateVideos WHERE YEAR(created) = :c0 GROUP BY MONTH(created) ',
'params' => [
':c0' => [
'value' => '2018',
'type' => null,
'placeholder' => 'c0'
]
],
但这会导致错误
Error: SQLSTATE[42000]: Syntax error or access violation:
1064 You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '(`id`)
FROM generate_videos GenerateVideos WHERE YEAR(created) = '2018' GROUP BY' at line 1
【问题讨论】:
标签: cakephp cakephp-3.x