php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5750 mysql_list_fields() returns no rows
Submitted: 2000-07-23 23:42 UTC Modified: 2000-07-24 02:06 UTC
From: bughuntr at ctelcom dot net Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.1pl2 OS: RedHat 6.2
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: bughuntr at ctelcom dot net
New email:
PHP Version: OS:

 

 [2000-07-23 23:42 UTC] bughuntr at ctelcom dot net
the following script produces no rows for mysql_list_fields.  the root user has permission to see fields in the db table on the mysql database.  This test failed identically on MySQL 3.22, and MySQL 3.23 beta:

<?

  $mysql_link = mysql_connect("localhost","root","mypassword");
  $mysql_result = mysql_list_dbs($mysql_link);

  $n = 0;
  while ($row = mysql_fetch_row($mysql_result))
     {
     print("mysql_result (list_dbs) = $mysql_result<br>");
     $n++;
     printf("Database number $n = %s<br>",$row[0]);

     $mr2 = mysql_list_fields("mysql","db",$mysql_link);
     print ("mr2=$mr2<br>");
     while ($rl = mysql_fetch_row($mr2))
       {
       $f++;
       print("Field number $f = $rl[0]<br>");
       }
     } // $row
  echo "<BR>";

  mysql_close($mysql_link);
?>

  the script put out the following.  I originally tried with multiple variables in the mysql_list_fields, but narrowed it down to a database and table I new existed:

mysql_result (list_dbs) = Resource id #2
Database number 1 = mysql
mr2=Resource id #3
mysql_result (list_dbs) = Resource id #2
Database number 2 = test
mr2=Resource id #4

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-07-24 00:50 UTC] bughuntr at ctelcom dot net
The functions mysql_list_dbs() and mysql_list_tables() work as expected.   even if mysql_select_db() is used, the mysql_list_fields() does not work.

This is ALSO broken in PHP 3.0.16.  

Unless, of course, I pulled a real stupid trick.  It is not beyond me.
 [2000-07-24 01:10 UTC] sniper at cvs dot php dot net
Please read the documentation.
http://www.php.net/manual/function.mysql-list-fields.php

<-cut->
mysql_list_fields() retrieves information about the given tablename. Arguments are the database name and the table name. A result pointer is returned which can be used with mysql_field_flags(), mysql_field_len(), mysql_field_name(), and mysql_field_type(). 
<-cut-> 

Your script has bug..

--Jani
 [2000-07-24 02:06 UTC] rasmus at cvs dot php dot net
Here is an example that illustrates how it should be written:

<?php
    mysql_connect("127.0.0.1","nobody","");
    $result = mysql_list_fields("php3","bugdb");
    $num = mysql_num_fields($result);
    for($i=0;$i<$num;$i++) {
        $name = mysql_field_name($result,$i);
        $type = mysql_field_type($result,$i);
        echo "$name $type\n";
    }
?>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu May 08 05:01:28 2025 UTC