Reputation: 791
I try to limit search result in Yii2 using Query class and where condition
$command=(new Query())
->select('*')
->from('ct_ostatniNaklady')
->where('pid=:pid',[':pid' => 1])
->createCommand()->sql;
var_dump($command);die;
However where command is not working properly. I get this result when I dump $command:
string(48) "SELECT * FROM `ct_ostatniNaklady` WHERE pid=:pid"
I don`t know why is :pid string not replacing by 1.
Using diffent syntax has no effect
->where(['pid'=>'1'])
result is quite common:
string(50) "SELECT * FROM `ct_ostatniNaklady` WHERE `pid`=:qp0"
What is correct way how to use where condition?
Upvotes: 2
Views: 841
Reputation: 18021
This is absolutely normal, that is how PDO works. And you use where properly.
If you want to generate SQL query with every parameter bound to a variable value use:
...->createCommand()->rawSql;
PS. I hope you use it only for debugging and some special cases because usually there is no need to generate raw query like that.
Upvotes: 2