Bug->Doc #61758 [Wfx->ReO]: mysql_fetch_field() incorrectly reports table name when using a table alias
| From: | philip@php.net | Date: | Wed, 18 Apr 2012 17:51:29 +0000 |
| Subject: | Bug->Doc #61758 [Wfx->ReO]: 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-8275@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: Wont fix
+Status: Re-Opened
-Type: Bug
+Type: Documentation Problem
Package: MySQL related
Operating System: Windows 7
PHP Version: 5.3.10
-Assigned To:
+Assigned To: philip
Block user comment: N
Private report: N
New Comment:
Marking as a doc bug for now (as suggested by Johannes), so I won't forget.
Previous Comments:
------------------------------------------------------------------------
[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