php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69474 ODBC: Query with same field name from two tables returns incorrect result
Submitted: 2015-04-17 10:05 UTC Modified: 2015-04-19 23:10 UTC
From: heinrich dot moser dot jun at moware dot at Assigned: ab (profile)
Status: Closed Package: ODBC related
PHP Version: 5.5.24 OS: Windows Server 2012 R2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: heinrich dot moser dot jun at moware dot at
New email:
PHP Version: OS:

 

 [2015-04-17 10:05 UTC] heinrich dot moser dot jun at moware dot at
Description:
------------
An ODBC query which created a correct result with PHP 5.5.23 produces an incorrect result with PHP 5.5.24. Tested on Windows Server 2012 R2 with SQL Server 2012.

How to reproduce:
1. Create an empty database and create the table with the test script given.
2. Create a system DSN called "forum" which connects to the database.
3. Execute the test script given with PHP 5.5.23 and 5.5.24 and compare the results.

Test script:
---------------
Database:
CREATE TABLE table1 (topic_id int);
CREATE TABLE table2 (topic_id int);
INSERT INTO table1 (topic_id) VALUES (1023);

Code:
<?php
date_default_timezone_set('Europe/Vienna');

$link = odbc_connect("forum", "", "");

$sql =
"SELECT table1.topic_id, table2.topic_id AS X
FROM table1 LEFT JOIN table2 ON table1.topic_id = table2.topic_id
WHERE table1.topic_id = 1023";

$result = odbc_exec($link, $sql);
$topic_data = odbc_fetch_array($result);
var_dump($topic_data);
odbc_free_result($result);
odbc_close($link);
?>

Expected result:
----------------
This is the script output I get with PHP 5.5.23:

array(2) {
  ["topic_id"]=>
  string(4) "1023"
  ["X"]=>
  NULL
}

Actual result:
--------------
This is the script output I get with PHP 5.5.24:

array(1) {
  ["topic_id"]=>
  NULL
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-17 11:17 UTC] heinrich dot moser dot jun at moware dot at
-Package: PDO ODBC +Package: ODBC related
 [2015-04-17 11:17 UTC] heinrich dot moser dot jun at moware dot at
Changed package from PDO ODBC to Database functions/ODBC related. Sorry for the initial miscategorization.
 [2015-04-17 14:07 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: ab
 [2015-04-17 14:07 UTC] cmb@php.net
Verified with MS Access Driver (6.01.7601.17632). According to the
ODBC trace[1] the driver doesn't recognize
SQL_DESC_BASE_COLUMN_NAME in the SQLColAttribute() calls. The issue
seems to have been introduced in commit #899362d[2]. Anatol, can
you please have a look.

[1] <https://gist.github.com/cmb69/37147767adf0514674ee>
[2] <https://github.com/php/php-src/commit/899362db6ed3131ff96f07e2d2b7f77c76ce9c40>
 [2015-04-17 18:48 UTC] ab@php.net
-Status: Verified +Status: Feedback
 [2015-04-17 18:48 UTC] ab@php.net
Please check this snapshot (or any later) http://windows.php.net/downloads/snaps/php-5.5/re09febb/ 

Thanks for triaging.
 [2015-04-17 23:03 UTC] cmb@php.net
The re09febb snapshot works fine with the Access driver.
 [2015-04-18 17:06 UTC] heinrich dot moser dot jun at moware dot at
Works fine with SQL Server as well. Thanks for the quick fix!
 [2015-04-19 23:10 UTC] ab@php.net
-Status: Feedback +Status: Closed
 [2015-04-19 23:10 UTC] ab@php.net
Thanks for the testing. Closing then :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC