Differences between bindParam () and bindValue () methods in phppdo

Source: Internet
Author: User
The bindParam () method is very similar to bindValue. The only difference is that the former uses a PHP variable to bind a parameter, while the latter uses one. Therefore, bindParam is the second parameter and can only be used with the variable name, but not with the variable. bindValue can be used as specific. $ Stm $ pdo-prepare (select * fromuserswhereuser

The bindParam () method is very similar to bindValue. The only difference is that the former uses a PHP variable to bind a parameter, while the latter uses one. Therefore, bindParam is the second parameter and can only be used with the variable name, but not with the variable. bindValue can be used as specific. $ Stm = $ pdo-prepare (select * from users where user =

The bindParam () method 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.

Therefore, bindParam is the second parameter. Only the variable name can be used, but not the variable value. bindValue can use the specific value.

$ Stm = $ pdo-> prepare ("select * from users where user =: user"); $ user = "jack"; // correct $ stm-> bindParam (": user ", $ user); // error // $ stm-> bindParam (": user "," jack "); // correct $ stm-> bindValue (": user ", $ user); // correct $ stm-> bindValue (": user "," jack ");

In addition, bindParam can be bound to an input/output variable in the stored procedure, as shown below

$ Stm = $ pdo-> prepare ("call func (: param1)"); $ param1 = "abcd"; $ stm-> bindParam (": param1 ", $ param1); // correct $ stm-> execute ();
After the execution of the stored procedure, the result can be directly reflected to the variable.

For the big data block parameters in the memory, the performance should be considered first.

Via http://anfirst.cn/archives/1030

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.