Dao Query Giving Error

I have the following query but it is giving no result while same query gives result when I execute it in MySQL. The query is


$connection = Yii::app()->db;

$sql = "SELECT sum(fuelLevel) from datatable where siteID = :site and arrival_time between :up and :low";

$command = $connection->createCommand($sql);

$command->bindValues(array(':site'=>$siteID, ':up'=>'2013-11-22 00:00:00', ':low'=>'2013-11-22 23:59:59'));

return $command->query();

What is wrong with this query?

Try with queryScalar() instead of query().

It is giving me the result as null when I do var_dump($command->queryScalar()) while same query in mysql


SELECT sum(fuelLevel) from datatable where siteID = 357804043678014 and arrival_time between '2013-11-22 00:00:00' and '2013-11-22 23:59:59'

gives correct result.

Enable query logging by turning on ‘enableProfiling’ property of your database connection (with YII_DEBUG enviromental variable set to true) and check the query in the application log.

I don’t use bindValues, instead I just pass the params array to one of query* method.