When I run an sql query using the ZF wrappers, all the numeric values return as strings. What do I need to change so the values will return in the same data type as they are in the DB?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I implemented a lot of the
Zend_Dbcode in Zend Framework.As other have stated, the reason that
Zend_Dbreturns strings instead of native PHP integers or floats is that PHP’s database extensions return strings. And the reason for that is that there might be no native PHP type to represent certain database type.For example, MySQL’s
BIGINTis a 64-bit signed integer. By default, the PHPinttype is limited to 32-bit values, so if you fetch data from the database and implicitly convert it toint, some values might be truncated. There are several other similar cases, forfloatand dates, etc.Using the string representation for all data types is the best way to remain simple and consistent, be safe about avoiding data loss, and avoid writing lots of vendor-specific special-case code to do data type mapping. That extra code would incur a performance penalty, too.
So if you have specific cases where you need database results to be mapped to native PHP data types, you should implement it yourself in your application code (e.g. in a custom
Zend_Db_Table_Rowclass).