bindParam() problem

$tableTest = 'stock';

$sql       = 'SELECT * 

              FROM :tableName';

$command = Yii::app()->db->createCommand($sql);

$command->bindParam( ":tableName", $tableTest, PDO::PARAM_STR );

$model = $command->query();

I try to break down this error. I tried permutation with bindValue(). I also tried giving it to query() in parameter:

$command->query( array(":tableName"=>$tableTest) ); //still gives me the same error :/





                        'emulatePrepare' => true,


I would love someone’s insight :lol:

Thank you for your time.

i`m not sure but replace @tablename instead of :tablename

Turns out bindParam() surround the token with quotes like:

SELECT * FROM 'tableName' 

which is not valid.

Aren’t you using this wrong? Isn’t that supposed to be used for binding values?

Yes he is using it wrong. See: