PHP: 7 PDO fetch(All) tries to convert types to associated type

后端 未结 1 502
广开言路
广开言路 2021-01-12 11:16

Today I found out that our code appears to be backward incompatible with a change in PDO. In PHP <5.6 the result sets from a PDOStatement through its functio

相关标签:
1条回答
  • 2021-01-12 11:37

    It is not PHP7 but the underlying driver called mysqlnd.
    Also, it is not a set of conversion rules but the way the transport protocol works: when both mysqlnd and native prepatred statements are used, then the binary transport protocol is used, means there is always an information about the data type. So the data just gets unpacked from the binary format right into a variable of the proper type - when PHP has an appropriate one, namely INTs and FLOATs (note that for the DECIMAL type string is returned, due to nature of this type).

    In case you don't want this behavior, there is a configuration option for this

    $pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
    

    will revert this behavior to just strings and nulls as before

    0 讨论(0)
提交回复
热议问题