Doc #61758 [ReO->Csd]: mysql_fetch_field() incorrectly reports table name when using a table alias

From: Date: Fri, 01 Jun 2012 06:46:30 +0000
Subject: Doc #61758 [ReO->Csd]: mysql_fetch_field() incorrectly reports table name when using a table alias
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8410@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61758&edit=1 ID: 61758 Updated by: philip@php.net Reported by: johnbillion at gmail dot com Summary: mysql_fetch_field() incorrectly reports table name when using a table alias -Status: Re-Opened +Status: Closed Type: Documentation Problem Package: MySQL related Operating System: Windows 7 PHP Version: 5.3.10 Assigned To: philip Block user comment: N Private report: N New Comment: Fixed in SVN, thank you for the report. Previous Comments: ------------------------------------------------------------------------ [2012-06-01 06:46:00] philip@php.net Automatic comment from SVN on behalf of philip Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=325919 Log: Documented PHP bug #61758 -- will report the alias name ------------------------------------------------------------------------ [2012-04-18 17:51:29] philip@php.net Marking as a doc bug for now (as suggested by Johannes), so I won't forget. ------------------------------------------------------------------------ [2012-04-18 10:53:56] johannes@php.net 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. ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#8410) next »