Reputation: 681
Having a problem trying to return field names from an MSSQL database via odbc in php. My query is as follows:
SELECT t.ID, t.end_user, ts.name 'status', tp.name 'priority' FROM tickets t INNER JOIN status ts ON ts.ID = t.status INNER JOIN priorities tp ON tp.ID = t.priority
Problem is, when I run this on the MSSQL server, the column names come up as expected (ID, end_user, status, priority), but when I run it on my page, I get "name" for both the status and priority columns.
Is there any rhyme or reason why it's not seeing my renaming of the columns? I tried using "AS" in the query, no luck.
Box is ubuntu running FreeTDS odbc driver version 7.2
Upvotes: 2
Views: 637
Reputation: 5192
I just spoke to J_D on the phone, (total internet stalk!), he suggested adding
+''
to a column name. That seems to circumvent this bug. The above code would have to be changed to
SELECT t.ID, t.end_user, ts.name+'' 'status', tp.name+'' 'priority' FROM tickets t INNER JOIN status ts ON ts.ID = t.status INNER JOIN priorities tp ON tp.ID = t.priority
which is a bit of a hack, but it will work. Apparently this is the result of some sort of bug in PHP when it tries to decipher ODBC results.
If anyone has a suggestion that does not involve altering SQL code, I personally would much appreciate it, saves me altering pages and pages of SQL code.
In other news, J_D, thank you for being such a gentleman on the phone to a random stranger.
Upvotes: 3