PHP和SQL Server - 字段名称被截断

PHP和SQL Server  - 字段名称被截断

问题描述:

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.

我发现来自我的SQL Server的结果会截断字段名称: p> \ n

  $ query =“SELECT some_really_really_long_field_name FROM ...”
 ... 
print_r($ row); 
 
array(
'some_really_really_long_field_n'=>'value'
)\  n  code>  pre> 
 
 

有谁知道如何避免这种行为? p>

我认为数据库驱动程序是ADODB。 p>

因此您不必计算:字段名称被截断为31个字符。 p>

SQL Server似乎并不介意长字段名称本身, 所以我只能假设在ADODB驱动程序的某处有一个char [32]字符串缓冲区,它不能包含长名称。 p> div>

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.

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.

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.