views:

335

answers:

3

I have discovered that results coming from my SQL Server are having the field names truncated:

$query = "SELECT some_really_really_long_field_name FROM ..."
...
print_r($row);

array(
    'some_really_really_long_field_n' => 'value'
)

Does anyone know how to avoid this behaviour?

I think the database driver is ADODB.

So you don't have to count: the field names are being truncated to 31 characters.

SQL Server doesn't seem to mind the long field names in itself, so I can only presume that there is a char[32] string buffer somewhere in the ADODB driver which can't contain the long names.

+1  A: 

easiest way to avoid truncated field names is to use shorter field names....

Sorry, that sounds like a crappy answer, but it's much cleaner, easier to read and maintain, and just better practice.

Luke Schafer
+4  A: 

You're probably using the decade-old, deprecated bundled MSSQL client. Use the new MSSQL driver for PHP from Microsoft or install the MSSQL client tools from your MSSQL server CD.

TML
"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."
TML
That worked really well.
too much php
+2  A: 

you can use an alias for your long field names, something like this:

$query = "SELECT some_really_really_long_field_name AS short_alias FROM ..."

this will work for your current problem. But I suggest using PDO MSSQL driver to connect to database.

farzad