$id = 1; //just as example
$sql = "SELECT * FROM sometable WHERE id = :id";
$command = Yii::app()->db->createCommand($sql);
$command = $command->bindValue(':id', $id);
CHtmlEx::out( $command->queryAll() ); //this CHtmlEx is just a helper utility class, and out is <pre> print_r() </pre>
print $command->text;
Although the query works fine the last line is not displaying the value 1 inside the WHERE
Shouldn’t I see this: SELECT * FROM sometable WHERE id = 1
instead I simply get my original sql string SELECT * FROM sometable WHERE id = :id
I wanted to feed the final SQL stament using bindValue (or bindParam) into CSqlDataProvider which takes a string as a first parameter.
That is, by the nature of prepared statements, not possible. Prepared statements are executed in two steps: the driver first sends the statement (with placeholders) to the DBMS, then sends the values for placeholders. The latter can be repeated with different values as many times as needed. You can use str_replace() or similar if you really need it, but I don’t think so