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]%'
can you tell me where is the problem?
Page 1 of 1
Can not select data
#2
Posted 02 June 2010 - 12:48 PM
Why not just do
and look at the actual query?
echo "SELECT COUNT(id) FROM Food WHERE dateExecuted BETWEEN '%$_GET[startdate]%' AND '%$_GET[enddate]%' ";
and look at the actual query?
#3
Posted 02 June 2010 - 01:33 PM
Try:
The indexes of $_GET are constants or strings??
"SELECT COUNT(id) FROM Food WHERE dateExecuted BETWEEN '%$_GET['startdate']%' AND '%$_GET['enddate']%' ";
The indexes of $_GET are constants or strings??
Don't say what you think, think what you say
The problem is communication! Excess of communication!
The problem is communication! Excess of communication!
#4
Posted 02 June 2010 - 02:46 PM
Can you try:
SELECT COUNT(id) FROM Food WHERE dateExecuted BETWEEN '%".$_GET[startdate]."%' AND '%".$_GET[enddate]."%' "
#6
Posted 03 June 2010 - 03:48 AM
Ouch! 
You are aware, that you circumvent PDO's automatic parameter quoting this way? You are opening a huge door for SQL injection!
Better approach:
Actually i don't get the point of using % here. But maybe i totally missed something.
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.
Share this topic:
Page 1 of 1

Help
















