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

后端 未结 3 709
甜味超标
甜味超标 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条回答
  •  -上瘾入骨i
    2021-02-08 20:33

    That's mainly for interacting with databases that require correct typing. For example, if you enable strict mode in MySQL, you will get errors (failed queries) instead of warnings when there are type mismatches.

    By default, MySQL does its best to convert data properly. But if you have ever seen 0000-00-00 in a date field, that is very likely the result of mysql trying to convert a string to a date and failing. In strict mode, the query would fail instead of trying to convert and using whatever the result is.

提交回复
热议问题