php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75534 Column aliases not working with FreeTDS
Submitted: 2017-11-16 19:48 UTC Modified: -
Votes:12
Avg. Score:4.2 ± 0.9
Reproduced:11 of 11 (100.0%)
Same Version:2 (18.2%)
Same OS:1 (9.1%)
From: chris at ocproducts dot com Assigned:
Status: Open Package: ODBC related
PHP Version: 7.1.11 OS:
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chris at ocproducts dot com
New email:
PHP Version: OS:

 

 [2017-11-16 19:48 UTC] chris at ocproducts dot com
Description:
------------
I am on a Mac using recent versions of FreeTDS (1.00.70, homebrew) and unixODBC (2.3.4, homebrew), connecting to SQL Server Express 2017 on Windows 10.

Column aliases (e.g. SELECT foo AS bar FROM something) are not respected. odbc_field_name will return 'foo', not 'bar'.

This is a known issue, but as far as I can see was never reporting directly to PHP as a bug.

Discussed on FreeTDS mailing list:
https://lists.ibiblio.org/pipermail/freetds/2010q2/025720.html
https://lists.ibiblio.org/pipermail/freetds/2012q1/027752.html

It is FreeTDS version specific, as at some point they improved their ODBC support to return original table field names rather than only aliases, with PHP now failing on assuming nothing will do that correctly.

Many asking questions across the web, and using kludgy workarounds like forced casts or noop expressions or downgrading the TDS protocol version:
https://stackoverflow.com/questions/10597898/php-unixodbc-freetds-select-field-as-name-does-not-work
https://github.com/ADOdb/ADOdb/issues/141
http://www.devnetwork.net/viewtopic.php?f=2&t=128778

I was able to resolve via a trivial patch, which is attached.

I am by no means an expert on ODBC. I can't confirm all ODBC implementations will correctly SQL_DESC_NAME, only that using it corrects my issue.


Patches

odbc-field-name-fix.diff (last revision 2017-11-16 19:48 UTC by chris at ocproducts dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-02 22:21 UTC] kuya1284 at gmail dot com
I just posted another workaround to this bug on SO that doesn't involve type-casting:

https://stackoverflow.com/a/55484317/2418233

It basically involves the use of variables before (or after) executing the SELECT query.
 [2023-06-29 03:00 UTC] samsnow at tjsnow dot com
Running debian bookworm with PHP 8.2.5 and  FreeTDS 1.3.17 and seeing this same bug. 

Working around it right now, using the "set a variable before you do a the query" trick, but it would be great to get this fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 00:01:30 2024 UTC