The example in this article describes a workaround in which PHP reads the ntext field return value of MSSQL as NULL. Share to everyone for your reference. The specific analysis is as follows:
Today in the use of PHP to connect the MSSQL database found that the contents of the ntext field can not be displayed, after the query found ntext field in PHP is not supported, the solution we just have to change the ntext field to text can be resolved.
If there is no ntext field in the table, you can use the following code:
Copy Code code as follows:
<?php
Connect to MSSQL
$link = Mssql_connect (' kallespcsqlexpress ', ' sa ', ' DSC ');
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 you have a ntext field in the table, and you can't change back to the text field, you can do the following:
1. Modify PHP.ini, open php.ini, and find the following code:
; mssql.textlimit = 4096 changed to Mssql.textlimit = 2147483647
Find:; mssql.textsize = 4096 changed to Mssql.textsize = 2147483647
2. You can use the Modify field, because the ntext and nvarchar fields in SQL Server store content in Unicode encoding, so PHP reads the ntext and nvarchar type fields with the MSSQL extension for an error.
If the Title field type is nvarchar,content field type is ntext, the following SQL statement will give an error.
The wrong code is as follows: Select Title,content from article
The correct:
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, if you do not support the host, the author has no way, the code is as follows:
Copy Code code as follows:
<?php
Include ("adodb/adodb.inc.php"); Contains ADODB class library files
$conn =newadoconnection (' Odbc_mssql '); Connecting to SQL Server databases
$conn->connect ("Driver={sql Server}"; Server=localhost;
Database=mydb; ", ' username ', ' password ');
?>
I hope this article will help you with your PHP program design.