php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1292 size of fetched array is not correct
Submitted: 1999-04-05 13:58 UTC Modified: 1999-05-11 09:06 UTC
From: geert at kemuri dot net Assigned:
Status: Closed Package: MySQL related
PHP Version: 3.0.7 OS: Linux
Private report: No CVE-ID: None
 [1999-04-05 13:58 UTC] geert at kemuri dot net
$res = mysql_db_query("adatabase","select name from persons");
$row = mysql_fetch_array($res);
$foo = sizeof($row);

$foo is not 1 (number of selected fields), but 2..
I'm having the problem with both stable and dev version of MySQL.

Same problem with mysql_fetch_object, but NOT with mysql_fetch_row.
I thought that these where the same :)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-05-11 08:56 UTC] sas at cvs dot php dot net
The mysql_fetch functions return an associative array which has both type of keys - names and numbers, so you can access your data either way.

Dividing the sizeof() result through 2 could help.
 [1999-05-11 09:06 UTC] rasmus at cvs dot php dot net
As of PHP-3.0.7 mysql_fetch_array() takes an optional second argument which is one of:
MYSQL_ASSOC, MYSQL_NUM or MYSQL_BOTH which determines how the 
array is built.  The default is MYSQL_BOTH which means both associative and
numerical entries are returned, and obviously MYSQL_ASSOC only creates
associative entries and MYSQL_NUM numerical ones.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 30 22:01:28 2024 UTC