binding does not work during console cron job

Hi,

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.

Cheers,

bettor

Untested on my part, but try passing a variable or use bindValue() instead.

/Tommy

Hi Tommy,

Thanks for the idea. It seems to work with bindValue. Do you have any idea why the difference?

Cheers,

bettor

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).

/Tommy

Also check out the PHP docs on these methods (Yii just wraps them up):

http://de3.php.net/manual/en/pdostatement.bindvalue.php

http://de3.php.net/manual/en/pdostatement.bindparam.php

I remember having some problems with bindParams() sometime, too. bindValue() always works, though.