PDO 在 PHP5.4 中以字符串形式返回整数列
问题描述
首先,我知道关于 SO 有各种类似的问题,例如 this 和 这个.但是,当我从表中获取值时,整数总是作为字符串获取.
First of all, I am aware that there are various similar questions on SO such as this and this. However, when I fetch values from a table, integers are always fetched as string.
我使用的是 PHP5.4 (5.4.16-1~dotdeb.1) 和 MYSQL5.5 (5.5.31+dfsg-0+wheezy1).这里 写到 PHP5 默认启用 MySQL Native Driver.4.0.但我仍然得到字符串值.
I am using PHP5.4 (5.4.16-1~dotdeb.1) and MYSQL5.5 (5.5.31+dfsg-0+wheezy1). It is written here that MySQL Native Driver is enabled by default in PHP5.4.0. But I still get string values.
我按如下方式初始化一个 PDO 对象.
I initialize a PDO object as follows.
当我插入时,我尝试使用 execute(array(...))
格式并且还使用了 bindValue(...,PDO::PARAM_INT)
,但它们没有任何区别.
When I insert, I tried to use execute(array(...))
format and also used bindValue(...,PDO::PARAM_INT)
, but they did not make a difference.
例如,这是我插入新行的方法.
For example, here is how I insert a new row.
这是我如何从表中获取行
Here is how I fetch rows from a table
当我在使用 PHP5.4.7 的 XAMPP for Linux 1.8.1 上测试时没有发生这种情况.我目前使用 nginx 而不是 Apache.
This did not occur when I tested on XAMPP for Linux 1.8.1 which uses PHP5.4.7. I currently use nginx instead of Apache.
怎么了?
推荐答案
要从带有 PDO 的 mysql 获取具有各自类型的整数和浮点数,您需要同时关闭基于 mysqlnd 的 PDO-mysql 和仿真模式.
To get integers and floats with respective types from mysql with PDO, you need both mysqlnd-based PDO-mysql and emulation mode turned off.
这篇关于PDO 在 PHP5.4 中以字符串形式返回整数列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!