What is the difference between PDOStatement::bindParam()
and PDOStatement::bindValue()
?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
The simplest way to put it (in terms of PHP):
bindParam:
referencebindValue:
variableHere are some I can think about :
bindParam
, you can only pass variables ; not valuesbindValue
, you can pass both (values, obviously, and variables)bindParam
works only with variables because it allows parameters to be given as input/output, by "reference" (and a value is not a valid "reference" in PHP) : it is useful with drivers that (quoting the manual) :With some DB engines, stored procedures can have parameters that can be used for both input (giving a value from PHP to the procedure) and ouput (returning a value from the stored proc to PHP) ; to bind those parameters, you've got to use bindParam, and not bindValue.
From Prepared statements and stored procedures
Use
bindParam
to insert multiple rows with one time binding:From the manual entry for
PDOStatement::bindParam
:So, for example:
or
You don't have to struggle any longer, when there exists a way lilke this:
The answer is in the documentation for
bindParam
:And
execute