#18619 [Opn->Bgs]: mysql_fetch_array returns numeric data as string

From: Date: Mon, 29 Jul 2002 14:16:22 +0000
Subject: #18619 [Opn->Bgs]: mysql_fetch_array returns numeric data as string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-15495@lists.php.net to get a copy of this message
ID: 18619 Updated by: georg@php.net Reported By: phpbugs@localpin.com -Status: Open +Status: Bogus Bug Type: MySQL related Operating System: Windows XP Home Edition PHP Version: 4.1.2 New Comment: MySQL always returns the row values as strings. Otherwise it would not possible to obtain bigint values e.g. Previous Comments: ------------------------------------------------------------------------ [2002-07-29 04:17:42] phpbugs@localpin.com 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 this bug report at http://bugs.php.net/?id=18619&edit=1

« previous php.bugs (#15495) next »