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" ); |
04 |
$stm ->bindParam( ":user" , $user ); |
06 |
//$stm->bindParam(":user","jack"); |
08 |
$stm ->bindValue( ":user" , $user ); |
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)" ); |
3 |
$stm ->bindParam( ":param1" , $param1 ); // Correct |
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