MySQL: Fetching Query Results as Native Data Types
This article addresses a common issue encountered when fetching MySQL query results: numeric values being returned as strings. The question arises on how to retrieve data in its native data type.
Unfortunately, using PHP 5.2 does not allow for native data types to be obtained. However, in PHP 5.3, the introduction of the mysqlnd driver (MySQL Native Driver) enables this functionality. When using Server-side Prepared Statements, mysqlnd returns integer columns as integers, not strings.
If server-side prepared statements are not feasible, another option involves creating a mapping system on the PHP side to convert database results to the desired PHP data types. However, this approach has limitations, especially when working with type-sensitive operators like === and !==.
The above is the detailed content of How to Fetch MySQL Query Results as Native Data Types in PHP?. For more information, please follow other related articles on the PHP Chinese website!