Edit report at https://bugs.php.net/bug.php?id=61758&edit=1

 ID:                 61758
 Comment by:         phpmpan at mpan dot pl
 Reported by:        johnbillion at gmail dot com
 Summary:            mysql_fetch_field() incorrectly reports table name
                     when using a table alias
 Status:             Open
 Type:               Bug
 Package:            MySQL related
 Operating System:   Windows 7
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

You have introduced an alias for a table in your query and the result contents 
reflects this. There is a good reason for such behaviour. Consider a following 
query:

SELECT *
FROM SomeTable AS workers
JOIN SomeTable AS managers ON managers.id = workers.boss


Previous Comments:
------------------------------------------------------------------------
[2012-04-17 19:03:31] johnbillion at gmail dot com

Description:
------------
The value of the 'Table' property returned by mysql_fetch_field() will be 
incorrect if a table alias was used in the SQL query.

Test script:
---------------
// It's assumed a MySQL resource has been established here

$result = mysql_query( 'SELECT * FROM table AS t' );
$i = 0;
while ( $i < mysql_num_fields( $result ) ) {
        $col_info[] = mysql_fetch_field( $result );
        $i++;
}
echo '<pre>' . print_r( $col_info, true ) . '</pre>';

Expected result:
----------------
The 'Table' property of the object output should be 'table'.

Actual result:
--------------
The 'Table' property of the object output is 't'.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61758&edit=1

Reply via email to