I’m not sure what is wrong here. When I execute the following query from MySQL CLI, I get this:
mysql> SELECT DATE_FORMAT( request_date, '%Y/%m' ) AS DateCreated,
-> COUNT(*) AS "Total Requests Created"
-> FROM requests
-> WHERE request_date >= '2015-01-01' AND request_date <= '2015-11-17'
-> GROUP BY DateCreated
-> ORDER BY DateCreated ASC;
+-------------+------------------------+
| DateCreated | Total Requests Created |
+-------------+------------------------+
| 2015/01 | 136 |
| 2015/02 | 207 |
| 2015/03 | 151 |
| 2015/04 | 172 |
| 2015/05 | 122 |
| 2015/06 | 157 |
| 2015/07 | 109 |
| 2015/08 | 123 |
| 2015/09 | 112 |
| 2015/10 | 97 |
| 2015/11 | 77 |
+-------------+------------------------+
11 rows in set (0.07 sec)
But when I use this same query in a
Yii::app()->db->createCommand()
$result = Yii::app()->db->createCommand()
->select('DATE_FORMAT(request_date,"%Y/%m") AS DateCreated, COUNT(*) AS "Total Requests Created"')
->from('requests')
->where('request_date >= :dBegin AND request_date <= :dEnd', array(':dBegin' => $_POST['date_from'], ':dEnd'=>$_POST['date_to'] ) )
->group('DateCreated')
->order('DateCreated ASC')
->limit('30')
->queryAll();
I get this when I do a var_dump()
Array
(
[date_from] => 2015-01-01
[date_to] => 2015-11-17
[yt0] => Submit
)
array(2) {
[0]=>
array(3) {
["DateCreated"]=>
string(7) "2015/02"
["Total Requests Created"]=>
string(1) "1"
}
[1]=>
array(3) {
["DateCreated"]=>
string(7) "2015/04"
["Total Requests Created"]=>
string(1) "4"
}
}
Any ideas?