php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16383 mysql_fetch_assoc returns strings only
Submitted: 2002-04-01 16:30 UTC Modified: 2002-04-02 18:45 UTC
From: suraev at tut dot by Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.1.1 OS: Win2000
Private report: No CVE-ID: None
 [2002-04-01 16:30 UTC] suraev at tut dot by
Hello, 

I found a strange behaviour while was working with mysql_fetch_array and mysql_fetch_assoc.
Even if table has an integer field, the result I got from functions listed above will list this value as string. 

php.ini 
magic_quotes_runtime = Off

simple example.
imagine that we
"create table tripreport (ID tinyint)"
then we "insert into MYTABLE (ID) values (1)"
then $r="select * from MYTABLE where ID=1"
then $f=mysql_fetch_assoc($r);
then $id=$f["ID"];
then echo gettype($id) will print "string".

is it an internal MySQL bug of PHP makes a mistake?

take care, Val

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-01 16:39 UTC] derick@php.net
The bug system is not the appropriate forum for asking support
questions. For a list of a range of more appropriate places to ask
for help using PHP, please visit http://www.php.net/support.php
 [2002-04-02 14:47 UTC] suraev at tut dot by
Why you decide that it's a support question?
No, you are not right. It's not important for me, as I found a way to make my scripts work fine even with this error.
But I still think that php development team should know that their function doesn't work the way it has to.  
If function has to return an array with integer value, but returns an array with string value - it's a bug.
That's why I wrote here.

Sincerely, Val suraev@tut.by
 [2002-04-02 15:02 UTC] derick@php.net
a. MySQL returns only strings with the C api call
b. PHP is typeless
c. it has been ages like this
d. In order to 'fix' this, we need to call atleast 4 new api calls, thus slowing down queries a LOT

This change is not going to happen.

Derick
 [2002-04-02 18:45 UTC] yohgaki@php.net
PostgreSQL module is the same.
All user inputs ($_POST,$_GET,etc) are string.

This design is good.
For example, PHP does not support large number,
but DB supports very large number. If PHP convert
numbers automatically, PHP cannot display db query
result correctly.

 [2003-04-06 08:49 UTC] yextir at gmx dot at
It would be great if the following would be added to the manual:

mysql_fetch_assoc returns strings only.

I thought it's a bug too.
But you are right, it doesn't matter if you know why it returns a string.

cu
daBart
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 19:01:31 2024 UTC