What's the point of using explicit data types in PDO::bindValue()
?
For example in either of the following forms there would be an SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'a'
$pdos->bindValue(':Value_For_An_Int_Col', 'a');//default arg for the third and opt par is PDO::PARAM_INT
$pdos->bindValue(':Value_For_An_Int_Col', 'a', PDO::PARAM_INT);
The PDOStatement::bindValue() function is an inbuilt function in PHP that is used to bind a value to a parameter. This function binds a value to the corresponding named or question mark placeholder in the SQL which is used to prepare the statement.
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.
When you need something like
SELECT * FROM ... LIMIT :intValues
That avoids to enclose the value inside quote, rising a SQL syntax error
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