I’ve setup a console command to run under a cron job. However, when I try to bind parameters my query does not seem to work (no errors) but if I directly place the value in the query all is fine. Any ideas on what I could’ve done wrong? Here is the situation:
the below code doesn’t work
$l=Yii::app()->db->createCommand("SELECT *
FROM table_name
WHERE status=:status");
$l->bindParam(':status','11');
$result=$l->queryAll();
the below code works:
$l=Yii::app()->db->createCommand("SELECT *
FROM table_name
WHERE status='11'");
$result=$l->queryAll();
When I check in the log that I monitor trace level the query is not logged, which means it hasn’t been executed.
The API reference clearly states it should be a variable
In the source there is a reference (’&’) to the parameter $value (only reached if param logging is enabled so perhaps that’s why you’ve not encountered the problem before).