How define the variable type in PDOStatement::bindValue()?

后端 未结 3 707
甜味超标
甜味超标 2021-02-08 19:36

The PDOStatement::bindValue() method offers a way to specify the type of the variable bound:

PDOStatement::bindValue ( $parameter , $value [, $da

3条回答
  •  走了就别回头了
    2021-02-08 20:10

    The data type parameter to PDOStatement::bindValue() isn't terribly useful. Essentially:

    • If you tell it PDO::PARAM_STR, it converts your value into a string.
    • If you tell it PDO::PARAM_INT and you pass a boolean, it converts it into a long.
    • If you tell it PDO::PARAM_BOOL and you pass it a long, it converts it into a boolean.

    Nothing else seems to be converted. See here for a quick look at the source code and a little better explanation. Perhaps most importantly, PDO will not throw an exception or produce an error if you pass data with a type that doesn't match the data type you passed.

提交回复
热议问题