Solution to why Text type fields in MSSQL database are truncated in PHP

巴扎黑
Release: 2016-11-10 10:07:40
Original
1446 people have browsed it

MSSQL database was used in PHP, and it happened that Text type fields were used in the database, so the problem arose. Every time I query the data from the database, it is always truncated inexplicably. At first, I thought that the PHP framework I used had a limit on the length of the string. Later I found that this was a stupid idea, because when submitting the data, I could Submit all the string contents to the database, but this phenomenon only occurs when reading, so I searched online to see if there are similar problems. I was lucky enough to find the solution on my first search, so I decided to repost it on my blog for the occasional needs of myself and the majority of PHP enthusiasts.
There are two solutions, as follows:
1. Modify php.ini to achieve this:
Open php.ini and you can see two options: mssql.textsize and mssql.textlimit:
; Valid range 0 - 2147483647. Default = 4096 .
;mssql.textlimit = 4096

; Valid range 0 - 2147483647. Default = 4096.
;mssql.textsize = 4096

You can see that the default configuration is 4096 bytes, which is often truncated to 4K , change it to the appropriate size, remove the semicolon in front, then save and restart the WEB server.

From the above two options, you can see that the range is: 0 - 2147483647 bytes.

if(MS_SQL_G(textlimit)!=-1){
sprintf(buffer,"%li",MS_SQL_G(textlimit));
if(DBSETOPT(mssql.link,DBTEXTLIMIT,buffer)==FAIL){
efree(hashed_details);
dbfreelogin(mssql.login);
RETURN_FALSE;
}
}
if(MS_SQL_G(textsize)!=-1){
sprintf(buffer,"SETTEXTSIZE%li",MS_SQL_G(textsize));
dbcmd(mssql.link,buffer);
dbsqlexec(mssql.link);
dbresults(mssql.link);
}
Copy after login

2. Execute SET TEXTSIZE before executing the SELECT query in PHP:

mssql_query("SETTEXTSIZE65536");

You can see from the above PHP source code that SET TEXTSIZE is actually executed.

If the above does not work, you can try to use the CAST function in the query statement.


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!