I don't understand the length option in a PDO PARAM_*
statement.
Does the length indicate an amount of required characters, or is it a max?
Example:
$sth->bindParam(2, $color, PDO::PARAM_STR, 12);
Does this require 12 characters, or is this limiting it to 12 characters? Or, am I completely misunderstanding what this is doing?
PDO::PARAM_STR. Represents SQL character data types. For an INOUT parameter, use the bitwise OR operator to append PDO::PARAM_INPUT_OUTPUT to the type of data being bound. Set the fourth parameter, length , to the maximum expected length of the output value.
bindParam is a PHP inbuilt function used to bind a parameter to the specified variable name in a sql statement for access the database record. bindValue, on the other hand, is again a PHP inbuilt function used to bind the value of parameter to the specified variable name in sql statement.
The PDOStatement::bindParam() function is an inbuilt function in PHP that is used to bind a parameter to the specified variable name.
PDO is an acronym for PHP Data Objects. PDO is a lean, consistent way to access databases. This means developers can write portable code much easier. PDO is not an abstraction layer like PearDB. PDO is a more like a data access layer which uses a unified API (Application Programming Interface).
It's an indication of how how much data you wish to receive in the output parameter, the server will not send more than this.
So, to answer your question, it's a limitation rather than a requirement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With