php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41303 mysql_fetch_array returns empty array
Submitted: 2007-05-06 12:25 UTC Modified: 2007-05-07 12:52 UTC
From: admin at shadyindustries dot biz Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.4.7 OS: Windows XP and Unix
Private report: No CVE-ID: None
 [2007-05-06 12:25 UTC] admin at shadyindustries dot biz
Description:
------------
mysql_fetch_array and mysql_fetch_assoc return empty arrays when, for the same query, mysql_num_rows returns 5 - the correct number.
also notable, the mysql_affected_rows causes a server malfunction for the same query.

I have tested it both on my 
public webserver (unix, unknown webserver, PHP 4, MySQL 4) and my home computer (Windows XP, Apache2, PHP 5, MySQL 5), 
thus this problem would appear to not be related to just one circumstance.

The really weird thing is that phpMyAdmin can read the database perfectly.

Reproduce code:
---------------
<?php

		$con = mysql_connect("####" ,"####" ,"####");
		if (!$con) {
			trigger_error("Unable to connect to mysql, MYSQL ERROR: " . mysql_error(),E_USER_ERROR);
		}
		if (!mysql_select_db("NuevasIslas", $con)) {
			trigger_error("Unable to open database, MYSQL ERROR: " . mysql_error(),E_USER_ERROR);
		}

while($row = mysql_fetch_array(mysql_query("SELECT * FROM `jaydev_config`"))) { 
	$config[$row['name']] = $row['value']; 
}

print "$config";

//print mysql_fetch_array(mysql_query("SELECT * FROM `jaydev_config`"));

?>

Expected result:
----------------
Array
(
[enabled_login] => 0
[enabled_register] => 1
[server_name] => JayDev
[url_base] => http://ni.shadyindustries.biz/jaydev/
[url_forum] => http://forum.shadyindustries.biz/viewforum.php?f=4
)  


Actual result:
--------------
Array

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-07 01:50 UTC] dayseye at 21cn dot com
should print() be print_r() ?
 [2007-05-07 03:07 UTC] scottmac@php.net
.
 [2007-05-07 09:36 UTC] admin at shadyindustries dot biz
yes, you were right, it should be print_r, however, that does not fix the actual problem.

the While statement causes a server malfunction.
 [2007-05-07 09:39 UTC] admin at shadyindustries dot biz
(sorry for the double post)

i believed the fact it was an "empty" array was causeing the problem, though, evidently it is not.

the ACTUAL problem is that the while statement causes the script execution to come to a standstill - no errors, it just times out.
 [2007-05-07 12:52 UTC] scottmac@php.net
That's because the while statement is never going to end, you'll re-run the query on each iteration of the loop.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Apr 30 04:01:29 2025 UTC