|  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: -
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: chris at ocproducts dot com
New email:
PHP Version: OS:


 [2017-11-16 19:48 UTC] chris at ocproducts dot com
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:

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:

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.


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


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:

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: Wed Jul 17 13:01:29 2024 UTC