CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty. The SQL statement executed wa

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty. The SQL statement executed was:

$sql = "SELECT count(a.id_alert) AS alert_counter,a.date_created,a.id_company,c.company

				FROM alert a JOIN alert_kid ak ON a.id_alert=ak.id_alert JOIN kid k ON ak.id_kid=k.id_kid JOIN company c ON c.id_company=a.id_company JOIN customer cs ON cs.id_customer=a.id_customer 


				WHERE true ".$addtoquery."


				GROUP BY date(a.date_created) LIMIT 10 OFFSET ".$page;


				print_r($sql); exit;


				$command=Yii::app()->db->createCommand($sql);


                $resultSet=$command->queryAll();

when i write this query in mysql directly then its give me proper result.but here its give me error mention above

$command=Yii::app()->db->createCommand($sql);

                $resultSet=$command->queryAll();

please help me thanx a lot

Please change your query according your requirment… i have changed most code…you have to change only wher code :)





$result = Yii::app()->db->createCommand()

                                ->select('count(a.id_alert) AS alert_counter,a.date_created,a.id_company,c.company')

                                ->from('alert a')

->join('alert_kid ak','a.id_alert = ak.id_alert')

->join('kid k','c.id_company=a.id_company')

->join('customer cs','cs.id_customer=a.id_customer')

->where('AccountId=:id', array(':id'=>Yii::app()->user->id))

->group('date(a.date_created)')

->limit(10)

->offset(10);


                $data = $result->query();

                foreach ($data as $out) return implode('<br />', $out);




Thnx a lot sir i have change the query and now it work properly once again thnx a lot sir