php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33060 mssql extension has a max length on returnable fieldnames
Submitted: 2005-05-18 22:51 UTC Modified: 2005-05-18 23:16 UTC
From: phpbugs at mfoxx dot myspamkiller dot com Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 5.0.4 OS: winxp, sp1
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpbugs at mfoxx dot myspamkiller dot com
New email:
PHP Version: OS:

 

 [2005-05-18 22:51 UTC] phpbugs at mfoxx dot myspamkiller dot com
Description:
------------
FYI:  I am running php 5.0.4 (binary distro) for windows, with apache 2.0.50 (binary distro), on a winXP sp1 machine.

If i execute:

select field1 as 'abcdefghijklmnopqrstuvwxyz0123456789' from mytable

in SQL Query Analyzer against a SQL Server 2000 database, i get the expected result that the field name is named that whole big long alias, 36 characters in length.  

However, when i execute the same query using mssql_query() in PHP, and i examine the results of mssql_fetch_object(), mssql_fetch_array(), or mssql_fetch_assoc(), the field name (alias) is truncated at 30 characters (it seems).

I do the same test against the mysql_xxx extension, and I get no truncation (i tested with upwards of about 100 chars in the field_name alias and all was fine).

Reproduce code:
---------------
$link = mssql_connect("localhost","sa","mypassword");
mssql_select_db("my_db",$link);

$query = "select field1 as 'abcdefghijklmnopqrstuvwxyz0123456789' from my_table";

$result = mssql_query($query);
print_r(mssql_fetch_object($result));

$result = mssql_query($query);
print_r(mssql_fetch_array($result));

$result = mssql_query($query);
print_r(mssql_fetch_assoc($result));

Expected result:
----------------
stdClass Object ( [abcdefghijklmnopqrstuvwxyz0123456789] => 0 ) Array ( [0] => 0 [abcdefghijklmnopqrstuvwxyz0123456789] => 0 ) Array ( [abcdefghijklmnopqrstuvwxyz0123456789] => 0 )

Actual result:
--------------
stdClass Object ( [abcdefghijklmnopqrstuvwxyz0123] => 0 ) Array ( [0] => 0 [abcdefghijklmnopqrstuvwxyz0123] => 0 ) Array ( [abcdefghijklmnopqrstuvwxyz0123] => 0 )


** notice that all 3 methods have a truncated field_name to 30 characters.  This obviously results in unexpected code problems when I have dynamic SQL queries being generated and its difficult to predict if an alias I assign to a field may exceed this limit, and if it does, i never get the value out in my result-set processing because the name doesn't match what i think it should.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-18 23:03 UTC] tony2001@php.net
"Note: In Windows, the DBLIB from Microsoft is used. Functions that return a column name are based on the dbcolname() function in DBLIB. DBLIB was developed for SQL Server 6.x where the max identifier length is 30. For this reason, the maximum column length is 30 characters. On platforms where FreeTDS is used (Linux), this is not a problem".
http://www.php.net/mssql
 [2013-04-15 13:58 UTC] rnowak at rafalnowak dot info
On Linux (Debian) Apache/2.2.21 (distrib), PHP/5.2.17 (distrib) and FreeTDS/1.12 
(distrib) problem occurs too. Truncate columns names to 30 chars.
 [2014-08-14 20:33 UTC] myself at myownserver dot org
This can be solved by changing freetds version to 8.0 in /etc/freetds/freetds.conf:

Change from:
    [global]
        # TDS protocol version
    ;   tds version = 4.2

To:
    [global]
        # TDS protocol version
        tds version = 8.0
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 21:01:31 2024 UTC