php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9839 opendir() before mysql_fetch_assoc() returns non-associative array
Submitted: 2001-03-19 11:16 UTC Modified: 2001-04-26 04:46 UTC
From: marshall at myself dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.4pl1 OS: Linux 6.2 on Alpha
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: marshall at myself dot com
New email:
PHP Version: OS:

 

 [2001-03-19 11:16 UTC] marshall at myself dot com
<?php

 // If the opendir call is before the connect, an associative array            
 // is NOT returned from mysql_fetch_assoc() - the closedir does not 
 // seem to have any effect on this phenomena.    
 //
 // It does NOT matter if the code is contained within the if() or
 // not. If the opendir() call occurs before the mysql_connect()
 // call, I get a farkled array from mysql_fetch_assoc().
 //
 // Changing the database and/or tables queried does not seem to
 // make a difference to the bug.
 
 
 // Change the 0 to 1 below to see this bug
 if (1) {
   $bizarrevar = opendir("/etc/");
   closedir($bizarrevar);
   unset($bizarrevar);   
 } 
  
  
 $dblink = mysql_connect("localhost","user","password");
 mysql_select_db("dbname", $dblink);
 
 $qresult = mysql_query("SELECT * FROM comment", $dblink);
 
 while ($rx = mysql_fetch_assoc($qresult, $dblink)) {
    while (list($k,$v) = each($rx)) {
       print(" $k = $v<BR>\n");
    }
 }   
     
?>

------------- End Script ------------

Data from phpinfo():

PHP was copmpiled with './configure' '--with-mysql' '--with-apache=../apache' '--enable-track-vars'

Virtual dir support is disabled


Apache Info: 

Apache Version Apache/1.3.19 
Apache Release 10319100 
Apache API Version 19990320 
Loaded Modules mod_php4, mod_setenvif, mod_auth, mod_access, mod_alias, mod_userdir, mod_actions, mod_imap, mod_asis, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_status, mod_negotiation, mod_mime, mod_log_config, mod_env, http_core 


MySQL Info:

Active Persistent Links 0 
Active Links 0 
Client API version 3.23.22-beta 
MYSQL_INCLUDE   
MYSQL_LFLAGS   
MYSQL_LIBS   

mysql.allow_persistent  On On 
mysql.default_host  no value no value 
mysql.default_password  no value no value 
mysql.default_port  no value no value 
mysql.default_socket  no value no value 
mysql.default_user  no value no value 
mysql.max_links  Unlimited Unlimited 
mysql.max_persistent  Unlimited Unlimited 


If you need additional information, please feel free to contact me via email at marshall@myself.com :)

Thanks


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-07 00:52 UTC] sniper@php.net
This is a bug in MySQL extension.

The mysql_fetch_assoc() function is supposed to take
only one argument. And you found this bug by passing
the $dblink variable which holds (after running opendir)
number 2 as value. The actual bug is in php_mysql_fetch_hash() function (in php_mysql.c) as there
should be a check for the second possible argument, that it's one of MYSQL_ASSOC, MYSQL_NUM or MYSQL_BOTH.

--Jani

 [2001-04-26 04:46 UTC] cardinal@php.net
mysql_fetch_assoc (And _fetch_row) now only takes one parameter in CVS.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 11:01:29 2025 UTC