Home>Article>Database> The solution to change the integer type of the field returned by querying mysql through PDO to the String type

The solution to change the integer type of the field returned by querying mysql through PDO to the String type

jacklove
jacklove Original
2018-06-09 10:41:32 2487browse

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:

Use php to obtain countries, provinces, cities, and surrounding data classes based on geographical coordinates

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn