PHP + MSSQL makes people miserable. These read PHP read MSSQL ntext field type problem again: When the ntext content is too long, actually read incomplete.
On the internet for a long time, are saying that PHP read ntext error, but did not find my page error, depressed. Later, it is said that PHP default maximum read only 4K content, the original is my content more than 4 K. Modify the method as
Under
1, the PHP upgrade to PHP5.
Fortunately, mine is already a php5.
2, adjust the parameters of the php.ini, the PHP default maximum read 4K can be changed a little larger.
; Valid Range 0-2147483647. Default = 4096.
; mssql.textlimit = 4096
; Valid Range 0-2147483647. Default = 4096.
; mssql.textsize = 20480
Put Mssql.textlimit and mssql.textsize in front of the ";" Go, and then change the default duty to larger, such as 20480 (20K)
3. Restart the Web server.
I think the exciting moment will come, run the PHP page, the effect is the same as before, the field data is not fully read out. Later found that the PHP support for ntext is not very friendly, to be converted to text. and then use
Convert (text, content) turned, had no effect to say, and nearly killed my IIS. I've been searching the internet for a long time without a solution. Just as I was about to give up, the idea of a trial made me change the way the database was connected. I took
Odbc_connect changed to Mssql_connect actually succeeded.
PHP link MSSQL problem ntext cannot read
Data that can be linked to a database but cannot be read. Google, Baidu After finally know that the original is PHP read MSSQL ntext field inverse value is empty, we suggest you can change the ntext field to text.
If there is no ntext field in the table, you can use the following code:
The code is as follows |
Copy Code |
Connect to MSSQL $link = Mssql_connect (' kallespcsqlexpress ', ' sa ', ' phpfi '); if (! $link! mssql_select_db (' php ', $link)) { Die (' Unable to connect or select database! ’); } Do a simple query, select the version of MSSQL and print it. $version = Mssql_query (' SELECT @ @VERSION '); $row = Mssql_fetch_array ($version); echo $row [0]; Clean up Mssql_free_result ($version); ? 》 |
If there is a ntext army field in the table, and it is not good to change back to the text field, you can:
1. Modify PHP.ini
Open php.ini
Found it:
; mssql.textlimit = 4096
Switch
Mssql.textlimit = 2147483647
Found it:
; mssql.textsize = 4096
Switch
Mssql.textsize = 2147483647
2. You can use the Modify field, because in SQL Server, the ntext and nvarchar fields are stored in Unicode encoding, so PHP reads with ntext and nvarchar type fields with MSSQL extension.
If the Title field type is nvarchar,content field type ntext, then the following SQL statement will give an error:
The wrong:
Select Title,content from article
Correct:
The code is as follows |
Copy Code |
Select CONVERT (varchar (255), title) as title, convert (text,content) as content from article |
{This method is not very practical, if the ntext content is too long after the conversion will lose data, also said the long article was truncated, and in the sql2008 to change the ntext to nvarchar (max) also not}
3. If you are a virtual host, you can use the ADODB component to read it. If your host does not support, the current author has no way.
The code is as follows |
Copy Code |
Include ("adodb/adodb.inc.php"); Contains the ADODB class library file $conn =newadoconnection (' Odbc_mssql '); Connecting to a SQL Server database $conn-"Connect (" Driver={sql Server}; Server=localhost;database=mydb; ", ' username ', ' password '); |
{Use ADODB one thing to note, the premise of using adodbphp Lian MSSQL is to drive the problem, 5.2.10 before, PHP comes with the driver only support MSSQL 7.0, if you want to support MSSQL 2000, will need to be MSSQL 2000 of Ntwdblib.dll (2000.80.2039.0) copied to System32 or PHP directory
5.2.11 Support MSSQL 2000, if required to support MSSQL 2005 and 2008, need to install Microsoft-provided driver
So if it's a virtual mainframe, it's basically no way
}
? >
Read MSSQL ntext field back to vacant
You can link to the database when you test, but you can't read the data. After finding the data found that the original PHP read MSSQL ntext field inverse value is empty, it is recommended that the ntext field can be changed to text.
If there is no ntext field in the table, you can use the following code:
The code is as follows |
Copy Code |
Connect to MSSQL $link = Mssql_connect (' kallespcsqlexpress ', ' sa ', ' phpfi '); if (! $link!mssql_select_db (' php ', $link)) { Die (' Unable to connect or select database! '); } Do a simple query, select the version of MSSQL and print it. $version = Mssql_query (' SELECT @ @VERSION '); $row = Mssql_fetch_array ($version); echo $row [0]; Clean up Mssql_free_result ($version); ?>
|
If there is a ntext army field in the table, and it is not good to change back to the text field, you can:
1. Modify PHP.ini
Open php.ini
Found it:
; mssql.textlimit = 4096
Switch
Mssql.textlimit = 2147483647
Found it:
; mssql.textsize = 4096
Switch
Mssql.textsize = 2147483647
2. You can use the Modify field, because in SQL Server, the ntext and nvarchar fields are stored in Unicode encoding, so PHP reads with ntext and nvarchar type fields with MSSQL extension.
If the Title field type is nvarchar,content field type ntext, then the following SQL statement will give an error:
The wrong:
Select Title,content from article
Correct:
The code is as follows |
Copy Code |
Select CONVERT (varchar (255), title) as title, convert (text,content) as content from article |
3. If you are a virtual host, you can use the ADODB component to read it. If your host does not support, the current author has no way.
The code is as follows |
Copy Code |
Include ("adodb/adodb.inc.php"); Contains the ADODB class library file $conn =newadoconnection (' Odbc_mssql '); Connecting to a SQL Server database $conn->connect ("Driver={sql Server}; Server=localhost;database=mydb; ", ' username ', ' password '); ?> |
http://www.bkjia.com/PHPjc/632192.html www.bkjia.com true http://www.bkjia.com/PHPjc/632192.html techarticle php + MSSQL makes people miserable. These read PHP read MSSQL ntext field type problem again: When the ntext content is too long, actually read incomplete. On the internet for a long time, are saying ...