在PHP中使用了MSSQL数据库,恰巧数据库中又使用了Text类型字段,于是问题产生了。每次从数据库中查询得到的数据总是被莫名的截断,一开始是以为我使用的PHP框架中对字符串的长度有所限制,后来发现这是个较愚蠢的想法,因为在提交数据时可以将字符串内容全部的提交到数据库中,只是读取时发生此现象,于是上网搜寻是否有类似的问题。运气还挺不错,第一次搜索就找到了解决的办法,遂决定将其转贴在我的Blog中,供自己和广大PHP爱好者的不时之需。
有两种解决方案,如下:
一、修改php.ini来实现:
打开php.ini,可看到mssql.textsize,mssql.textlimit两个选项:
; Valid range 0 - 2147483647. Default = 4096.
;mssql.textlimit = 4096
; Valid range 0 - 2147483647. Default = 4096.
;mssql.textsize = 4096
可以看到默认配置为4096字节,也就是经常碰到的被截断为4K,将之改为合适的大小,去掉前面的分号,然后保存并重起WEB服务器即可。
从上面两个选项可看到范围为:0 - 2147483647字节。














二、 在PHP中执行SELECT查询之前执行SET TEXTSIZE:

从上面PHP源代码中可看到其实也是执行SET TEXTSIZE的。