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.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3