PDO query mysql returns field integer type into String type solution
When using PDO to query mysql database, after executing prepare and execute, the returned field data will all change into character type .
For example, the id in the database isInt, and the query returns the typeString.
For weakly typed languages like php, it has little impact. When the API returns data, if the type is inconsistent with the database, the impact will be great for strong types such as Java and Objective C.
Solution:
setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);?>
The role of these two settings
PDO::ATTR_STRINGIFY_FETCHESConvert the value to a string when extracting.
PDO::ATTR_EMULATE_PREPARESEnables or disables emulation of prepared statements.
MorePDO setAttributePlease refer to: php Chinese website
This article explains the solution to change the integer type of the field returned by mysql through PDO to the String type, more related Please pay attention to php Chinese website for content.
Related recommendations:
How to use glob Methods related to traversing all files in a folder
Explanation on PHP floating point number comparison method
The above is the detailed content of The solution to change the integer type of the field returned by querying mysql through PDO to the String type. For more information, please follow other related articles on the PHP Chinese website!