php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25627 mysql_fetch_array (); returns NULL on connection/querie failure
Submitted: 2003-09-22 09:00 UTC Modified: 2003-09-23 04:06 UTC
From: MDonatas at centras dot lt Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.3 OS: Windows XP
Private report: No CVE-ID: None
 [2003-09-22 09:00 UTC] MDonatas at centras dot lt
Description:
------------
In documentation for mysql_fetch_array (); it says "Returns an array that corresponds to the fetched row, or FALSE if there are no more rows."

But if connection to database fails or querie is somewhat wrong, this function will return NULL which is defenitely wrong.

if you have script like

while (FALSE !== ($info = mysql_fetch_array ($result)))
{
  ...
}

then it will start infinite loop.

Reproduce code:
---------------
<?
  //WARNING! This will start infinite loop
  
  while (FALSE !== ($info = mysql_fetch_array ($result)))
  {
  }
?>

Expected result:
----------------
Should return FALSE on any failures

Actual result:
--------------
Returns NULL on failures.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-22 18:52 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You are supposed to provide correct arguments to the function. If they query has failed you should return value then, not pass it to another function.
 [2003-09-23 04:06 UTC] MDonatas at centras dot lt
Thank you for your fast reply.

I've checked the manual once again but I still couldn't find anything about NULL being returned. So either the manual needs updating or the function, which would solve some missunderstandings.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 18 00:01:28 2024 UTC