The differences between bindParam and bindValue and their usage in Yii2, bindparamyii2
BindParam () is very similar to bindValue. The only difference is that the former uses a PHP variable to bind a parameter, while the latter uses a value. For the big data block parameters in the memory, the performance should be considered first.
Query a piece of data by id and filter the id:
$id = 1;$result = Yii::$app->db->createCommand("select * from product where id=:id")->bindParam(":id",$id,\PDO::PARAM_INT)->queryAll();$result = Yii::$app->db->createCommand("select * from product where id=:id")->bindParam(":id",$id,\PDO::PARAM_STR)->queryAll();
Update a piece of data:
$id = 1;$name = 'xiaoming';$result = Yii::$app->db->createCommand("update product set name=:name where id=:id")->bindParam(':id',$id,\PDO::PARAM_INT)->bindParam(':name',$name,\PDO::PARAM_INT)->execute();
An error is reported as follows:
$result = Yii::$app->db->createCommand()->delete('product',['name'=>':value'],'id=:id')->bindValue(':id',1,\PDO::PARAM_INT)->bindParam(':value',$user,\PDO::PARAM_INT)->execute();
The difference between bindParam and bindValue and the usage details in Yii2 are all the content that I have shared with you. I hope to give you a reference and support for the customer's house.