php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15399 returning fields with appropriate type from MySQL
Submitted: 2002-02-06 05:17 UTC Modified: 2002-07-16 09:13 UTC
From: a at simongrant dot org Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.1.1 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: a at simongrant dot org
New email:
PHP Version: OS:

 

 [2002-02-06 05:17 UTC] a at simongrant dot org
As a recent starter with PHP and MySQL, I have been caught out for too long not realising that all fields returned using mysql_fetch_row (and presumably others) are returned as strings. It would be really useful if there were a variant mysql call which returned the field with an appropriate type. Is the problem that PHP doesn't have enough types? Well, a fairly good job could be done on it anyhow.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-24 07:30 UTC] sander@php.net
PHP has no (strict) types so it doesn't matter which types mysql_fetch_row & co return.
 [2002-02-24 10:42 UTC] a at simongrant dot org
It does matter to me. The problem arose for me by my using the & operator on the returned values. Though I might have expected it, no automatic cast was done to an integer, with nonsense results. Instead, any value I want to use as a bit array to do bit manipulation on I have to cast (laboriously, error-prone) to (integer). That's a pain.
All I'm asking for is to have a fetch command that returns a sensible type appropriate to the type stored in the database.
 [2002-07-16 02:06 UTC] georg@php.net
This is not possible cause the mysql c-api function 
mysql_fetch_row (which is used in the mysql extension) 
always returns strings.

 [2002-07-16 08:46 UTC] a at simongrant dot org
Many thanks for this clarification.

For people like me, it would be helpful to emphasise very clearly in the relevant manual pages that mysql_fetch_row etc. only returns strings. I've got used to it now, but only after quite some experience, and it still catches me out occasionally through my negligence.

I will see if I can find a place to add that comment myself.
 [2002-07-16 09:13 UTC] sniper@php.net
not possible -> bogus (at least not possible right now)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC