简体   繁体   English

MS SQL / PHP截断结果文本

[英]MS SQL/PHP truncating result text

I have a MS SQL query that is selecting a field and it is being chopped off for some reason it is cutting off text at 257 characters. 我有一个MS SQL查询正在选择一个字段,由于某种原因,它正在切断257个字符的文本。

Is there some kind of default cut-off for retrieving results with MSSQL and PHP? 使用MSSQL和PHP检索结果是否存在某种默认截止?

I'm honestly clueless as to why this is happening. 说实话,我真的很无能为力。 ANY guidance would be greatly appreciated 任何指导将不胜感激

The field type is "char" 字段类型是“char”

Here is a screen shot of my MS SQL config from phpinfo() alt text http://www.aaacoloautosource.com/mssql_config.png 这是我的MS SQL配置的屏幕截图,来自phpinfo() alt text http://www.aaacoloautosource.com/mssql_config.png

could it be the mssql.textlimit or mssql.textsize value? 它可能是mssql.textlimitmssql.textsize值吗?

The problem is most likely that you are using TDS protocol version 4.2. 问题很可能是您使用的是TDS协议版本4.2。 You should upgrade to at least 7.0 by setting this in /etc/freetds.conf: 您应该通过在/etc/freetds.conf中设置它来升级到至少7.0:

tds version = 7.0

The limitations of version 4.2 are: 版本4.2的限制是:

  • ASCII only 仅限ASCII
  • RPC is not supported. 不支持RPC。
  • BCP is not supported. 不支持BCP。
  • varchar fields are limited to 255 characters. varchar字段限制为255个字符。 If your table defines longer fields, they'll be truncated. 如果您的表定义了更长的字段,它们将被截断。
  • dynamic queries (also called prepared statements) are not supported. 不支持动态查询(也称为预准备语句)。

For more details, see http://freetds.schemamania.org/userguide/choosingtdsprotocol.htm 有关详细信息,请参阅http://freetds.schemamania.org/userguide/choosingtdsprotocol.htm

Somehow the datatype is "char", which apparently is limited to 255 characters. 不知何故,数据类型是“char”,显然限制为255个字符。 BUT the DB is storing more than 255 characters. 但是DB存储的字符超过255个。

Converting the field to TEXT works perfectly for some reason. 由于某种原因,将字段转换为TEXT非常有效。

SELECT CONVERT(TEXT,fld_name) FROM TABLE_NAME

From the mysql manual : mysql手册

The length of a CHAR column is fixed to the length that you declare when you create the table. CHAR列的长度固定为您在创建表时声明的长度。 The length can be any value from 0 to 255. 长度可以是0到255之间的任何值。

In my version of MYSQL, I cannot set a char field to longer than 255 characters, as per the above specification. 在我的MYSQL版本中,根据上面的规范,我不能将char字段设置为超过255个字符。

Is there any reason you need to use char? 你需要使用char吗? Try using text or blob or varchar instead. 请尝试使用text或blob或varchar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM