#18619 [NEW]: mysql_fetch_array returns numeric data as string
| From: | phpbugs at localpin dot com | Date: | Mon, 29 Jul 2002 08:17:43 +0000 |
| Subject: | #18619 [NEW]: mysql_fetch_array returns numeric data as string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-15475@lists.php.net to get a copy of this message | ||
From: phpbugs@localpin.com
Operating system: Windows XP Home Edition
PHP version: 4.1.2
PHP Bug Type: MySQL related
Bug description: mysql_fetch_array returns numeric data as string
I am not 100% that this is not 'working as designed', but it seems to me
that if that is the case then the design needs to be looked at...
When I get numeric fields from a MySQL database, they are returned as
strings. This does not matter most of the time (since you are only going
to pass them on to some other routine which only cares about the value,
not the datatype), but occassionally causes a headache.
For example,
$query = "SELECT cat_key FROM category";
$result = mysql_query($query);
if ($result) {
while (list($cat_key) = mysql_fetch_array($result)) {
$cat_keys[] = $cat_key;
}
}
The values in the array of $cat_keys in the above example will be string,
even if the $cat_key field in the database is defined as, for example,
integer.
Of course it is possible to force it to be numeric by making the line:
$cat_keys[] = (int) $cat_key;
But shouldn't PHP be making the datatype numeric for a numeric field?
Thanks!
Hugh Prior
--
Edit bug report at http://bugs.php.net/?id=18619&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18619&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18619&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18619&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18619&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18619&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18619&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18619&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18619&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18619&r=globals