Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of using explicit data types in PDO::bindValue()?

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);
like image 685
MTVS Avatar asked Nov 27 '12 22:11

MTVS


People also ask

What does bindValue do in PHP?

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.

What is PDO :: Param_str in PHP?

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.


1 Answers

When you need something like

SELECT * FROM ... LIMIT :intValues

That avoids to enclose the value inside quote, rising a SQL syntax error

like image 70
dynamic Avatar answered Oct 22 '22 18:10

dynamic