Difference between bindparam () and bindvalue in PDO

Source: Internet
Author: User

Confijin Article Source Read 2491 to 2 Transfer to my Library:
Differences between bindparam () and bindvalue () methods in PHP PDO

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.

01 $stm $pdo->prepare("select * from users where user = :user");
02 $user "jack";
03 // Correct
04 $stm->bindParam(":user",$user);
05 // Error
06 //$stm->bindParam(":user","jack");
07 // Correct
08 $stm->bindValue(":user",$user);
09 // Correct
10 $stm->bindValue(":user","jack");

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

1 $stm $pdo->prepare("call func(:param1)");
2 $param1 "abcd";
3 $stm->bindParam(":param1",$param1); // Correct
4 $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.

Difference between bindparam () and bindvalue in PDO

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.