When I executed this command, display shows 0, but in mysql I get the data.
<?php
$TTCS = Yii::app()->db->createCommand("SELECT COUNT(id) FROM Food WHERE dateExecuted BETWEEN ‘%$_GET[startdate]%’ AND ‘%$_GET[enddate]%’ ")->queryScalar();
echo $TTCS
?>
I think I have problem this — ‘%$_GET[startdate]%’ AND ‘%$_GET[enddate]%’
You are aware, that you circumvent PDO’s automatic parameter quoting this way? You are opening a huge door for SQL injection!
Better approach:
$command=Yii::app()->db->createCommand('... BETWEEN :startdate AND :enddate');
$command->bindParam(':startdate','%'.$_GET['startdate'].'%');
$command->bindParam(':enddate','%'.$_GET['enddate'].'%');
Actually i don’t get the point of using % here. But maybe i totally missed something.