Retrieving MySQL Query Results in Native Data Types
This question centers around the issue of obtaining MySQL query results in their native data types when using PHP. Specifically, a developer is encountering numeric values being returned as strings, despite using mysql_fetch_row() and mysql_result().
The Answer
In PHP 5.3, this issue can be resolved by employing the mysqlnd (MySQL Native Driver) driver. When utilizing server-side prepared statements with mysqlnd, query results are returned in their native data types. However, for non-prepared statements, the developer may consider using an ORM or mapping system to convert the results to appropriate PHP data types.
Additional Notes
The use of === and !== operators, which are type-sensitive, may not be feasible with this approach due to the potential type mismatch between database and PHP results.
The above is the detailed content of Why are MySQL query results returned as strings in PHP and how can I retrieve them in their native data types?. For more information, please follow other related articles on the PHP Chinese website!