PHP & SQL Server - field names truncated

I found that the results obtained from my SQL Server have truncated field names:

$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 behavior?

I think the database driver is ADODB.

This way you don't have to consider: field names are truncated to 31 characters.

SQL Server doesn't seem to have long field names in mind by itself, so I can only assume there is a char [32] buffer in the ADODB driver that cannot hold long names.

+1


a source to share


3 answers


You are probably using a decade old, outdated MSSQL batch client. Use the new MSSQL driver for PHP from Microsoft, or install the MSSQL client tools from your MSSQL server CD.



+5


a source


you can use an alias for 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 the PDO MSSQL driver to connect to the database.

+2


a source


The easiest way to avoid truncated field names is to use short field names ....

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

+1


a source







All Articles