From:             beckman at purplecow dot com
Operating system: FreeBSD 5.0-RELEASE #0
PHP version:      4.3.3
PHP Bug Type:     MySQL related
Bug description:  mysql_list_fields does NOT use link_identifier

Description:
------------
Synopsis: mysql_list_fields should ignore the currently selected database,
since the name of the database is clearly being passed to the function. 
But the function uses the currently selected database rather than the
database specified in the function.  

Evidence:
Using MySQL 4.0.14 and PHP 4.3.3, mysql_list_fields($db, $tbl,
$link_identifier) uses the most recent connection to mysql, not the
connection specified in $link_identifier.

I've tried to reproduce this problem, and the only place I can is in
phpMyAdmin 2.5.4 dev.

It seems that mysql_list_fields ignores the link_identifier it is passed
and uses either DB "mysql" or uses the most recent connection.

When testing, here's what I did.

In phpMyAdmin, I selected my database, then selected "Query."

I now get an error saying "#1146 - Table 'mysql.assignments' doesn't
exist".

So I got into the code in db_details_qbe.php.  On line 132, this line
occurs:

    $fld_results     = @PMA_mysql_list_fields($db, $tbl) or
PMA_mysqlDie(PMA_mysql_error(), 'PMA_mysql_list_fields(' . $db . ', ' .
$tbl . ')', FALSE, $err_url);

The function is as this:

    function PMA_mysql_list_fields($database_name, $table_name,
$link_identifier = FALSE) {
        if ($link_identifier != FALSE) {
            return mysql_list_fields(PMA_convert_charset($database_name),
PMA_convert_charset($table_name), $link_identifier);
        } else {
            return mysql_list_fields(PMA_convert_charset($database_name),
PMA_convert_charset($table_name));
        }
    }

When echo'ed, it was executed as "mysql_list_fields("crt", "assignments").
 So I decided I should try using the link identifier explicitly.

    $fld_results     = @PMA_mysql_list_fields($db, $tbl, $userlink) or
PMA_mysqlDie(PMA_mysql_error(), 'PMA_mysql_list_fields(' . $db . ', ' .
$tbl . ')', FALSE, $err_url);

Got the same error.  So then I was concerned that $userlink wasn't the
correct link to the database in question.  So I did this on line 131:

   $r = mysql_query("Show tables from ".$db, $userlink);
   while($row = mysql_fetch_array($r)) { print_r($row); }

And it gave me a list of all the tables, including assignments (first). 
So I dropped the $userlink from the above code and tried it again. 
Worked.  So then I thought, maybe $userlink isn't using the
mysql_select_db that I think it is.  So I changed the query to "select
count(*) from assignments" and it failed, so I assume $userlink is working
off of the assumption that the currently selected database is "mysql."  

mysql_list_fields should ignore the currently selected database, since the
name of the database is clearly being passed to the function.  But the
function uses the currently selected database rather than the database
specified in the function.  

Reproduction:
I wasn't able to use a simple $link = mysql_connect, mysql_select_db, then
see mysql_list_fields fail.  I went through the phpMyAdmin code as
completely as possible, but I'm fairly certain that it is a fault in the
php functions, based on the documentation.  I believe it may be related to
or similar to Bug #22661.


-- 
Edit bug report at http://bugs.php.net/?id=25460&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25460&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25460&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25460&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25460&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25460&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25460&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25460&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25460&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25460&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25460&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25460&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25460&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25460&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25460&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25460&r=gnused

Reply via email to