Bug #44341 [Com]: PDOStatement::fetch() always returning string values
| From: | stephen at flowsa dot com | Date: | Thu, 21 Nov 2013 14:41:30 +0000 |
| Subject: | Bug #44341 [Com]: PDOStatement::fetch() always returning string values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182878@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=44341&edit=1
ID: 44341
Comment by: stephen at flowsa dot com
Reported by: cortexd at wanadoo dot fr
Summary: PDOStatement::fetch() always returning string values
Status: Not a bug
Type: Bug
Package: PDO related
Operating System: Windows XP
PHP Version: 5.2CVS-2008-03-05 (snap)
Block user comment: N
Private report: N
New Comment:
I had this issue this week and though I agree that it is not a PHP bug (but rather a driver issue)
it is helpful to note that there is a solution.
I found that my version of PHP installed on Ubuntu was using the "libmysql" driver and not
the "mysqlnd" driver. The "mysqlnd" driver will return number columns as number
types.
I removed the old driver ("apt-get remove php5-mysql") and installed the
"mysqlnd" driver ("apt-get install php5-mysqlnd") which solved the issue for me.
It's also important to ensure that PDO has these to settings set:
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
Hopefully that is helpful to anyone who has the same issue.
Previous Comments:
------------------------------------------------------------------------
[2013-11-16 10:56:24] linzuxiong1988 at gmail dot com
I think it is a bug too ,
We can recode the msyql-driver code and compile to Fix it.
@ rasmus@php.net , Maybe you think php is leak type languange .
But now we must compati the IOS client/ Android client , and so on ...
php-src/ext/pdo/pdo_mysql_driver.c ?
------------------------------------------------------------------------
[2013-04-28 13:51:24] rasmus@php.net
bulgur_wheat at hushmail dot com can you explain what you think we should be
fixing? As Ilia said years ago, PDO::ATTR_STRINGIFY_FETCHES only affects things
if the underlying database driver is able to return native types. Most db drivers
don't do this. They always return strings no matter what the column type is. We
can't fix that aspect since we do not control these drivers.
------------------------------------------------------------------------
[2013-04-28 09:47:03] bulgur_wheat at hushmail dot com
Had to register a new email address just to comment on this. For the past 8 years, I've spent
every day of my life coding in PHP.
The manner in which this bug was dismissed is absolutely outrageous. Fix it.
------------------------------------------------------------------------
[2011-09-19 10:27:04] aphax91 at gmail dot com
"Thank you for taking the time to write to us, but this is not
a bug."
So you mean that when the value of a mySql int field is naturally returned as a string, this is not
considered like a bug, is that a joke ? :)
Also, if you force the conversion of integers into strings, why the PDO driver
PDO::ATTR_STRINGIFY_FETCHES isn't supported to let us the choice ? I don't understand the
logic behind this...
Is it planned to fix this ?
Thanks.
------------------------------------------------------------------------
[2011-04-17 10:36:58] php_nospam at ramihyn dot sytes dot net
Looking at the source of pdo_mysql shows, that pdo_mysql_stmt_get_col() returns a ZVAL reference
instead of copying a string, if mysqlnd is in use. So why do the builds available for download still
all have that bug?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=44341
--
Edit this bug report at https://bugs.php.net/bug.php?id=44341&edit=1