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

 ID:                 61758
 Updated by:         johan...@php.net
 Reported by:        johnbillion at gmail dot com
 Summary:            mysql_fetch_field() incorrectly reports table name
                     when using a table alias
-Status:             Open
+Status:             Wont fix
 Type:               Bug
 Package:            MySQL related
 Operating System:   Windows 7
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

Please use mysqli and mysqli_fetch_field() instead of the old mysql extension. 
The old MySQL extension only receives bug fixes no new "features". mysqli will 
report two fields, "table", which has the aliased name, and "origtable", which 
has the original name.


Previous Comments:
------------------------------------------------------------------------
[2012-04-18 03:27:30] phpmpan at mpan dot pl

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

------------------------------------------------------------------------
[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