|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 14:00:01 2025 UTC |
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