This time to bring Bindparam and Bindvalue in Yii2 in the use of steps to resolve, Bindparam and Bindvalue in the Yii2 used in the attention of what, the following is the actual case, together to see.
Bindparam () and Bindvalue () are very similar. The only difference is that the former uses a PHP variable binding parameter, and the latter uses a value. For those large data block parameters in memory, in the performance considerations, the former should be used preferentially.
Query one piece of data based on ID and filter the ID:
$id = 1; $result = Yii:: $app->db->createcommand ("SELECT * from product where Id=:id")->bindparam (": id", $id, \pdo ::P aram_int)->queryall (); $result = Yii:: $app->db->createcommand ("SELECT * from product where Id=:id") Bindparam (": id", $id, \pdo::P aram_str)->queryall ();
Update one piece of data:
$id = 1; $name = ' xiaoming '; $result = Yii:: $app->db->createcommand ("Update product set Name=:name where Id=:id")-> ; Bindparam (': Id ', $id, \pdo::P aram_int)->bindparam (': Name ', $name, \pdo::P aram_int)->execute ();
The following wording will be an error
$result = Yii:: $app->db->createcommand ()->delete (' Product ', [' name ' = ': Value '], ' id=:id ') Bindvalue (': Id ', 1,\pdo::P aram_int)->bindparam (': Value ', $user, \pdo::P aram_int)->execute ();
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
Php+js How to make real-time search hints
Php method for sorting arrays based on the size of a key value