too much php
too much php

Reputation: 90988

PHP & SQL Server - field names truncated

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.

Upvotes: 1

Views: 1625

Answers (3)

farzad
farzad

Reputation: 8855

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.

Upvotes: 2

TML
TML

Reputation: 12966

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.

Upvotes: 5

Luke Schafer
Luke Schafer

Reputation: 9265

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.

Upvotes: 1

Related Questions