php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18619 mysql_fetch_array returns numeric data as string
Submitted: 2002-07-29 04:17 UTC Modified: 2002-07-29 10:16 UTC
From: phpbugs at localpin dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.1.2 OS: Windows XP Home Edition
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpbugs at localpin dot com
New email:
PHP Version: OS:

 

 [2002-07-29 04:17 UTC] phpbugs at localpin dot 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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-29 10:16 UTC] georg@php.net
MySQL always returns the row values as strings. Otherwise it would not possible to obtain bigint values e.g.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 00:01:29 2024 UTC