Bindparam and Bindvalue in the Yii2 of the use of the detailed

Source: Internet
Author: User
Tags yii
This time to bring you bindparam and Bindvalue in Yii2 in the use of detailed, Bindparam and bindvalue in the use of the YII2 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 reserved Key value + Merge array

How to exclude duplicate values in a two-dimensional array

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.