The reverse return value of ntext field for php to read mssql is null. When using php to connect to the mssql database today, the content of the ntext field cannot be displayed. After query, it is found that the ntext field is not supported in php, solution: we only need to change the ntext field to te. when we connect to the mssql database using php today, we find that the content of the ntext field cannot be displayed. After query, we find that the ntext field is not supported in php, the solution is to 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: |
|
// 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 // MSSQL and print it. $ Version = mssql_query ('select @ version '); $ Row = mssql_fetch_array ($ version ); Echo $ row [0]; // Clean up Mssql_free_result ($ version ); ?> |
If the table contains an ntext military field and it is difficult to modify the text field, you can:
1. modify php. ini
Open php. ini
Find:
The code is as follows: |
|
; Mssql. textlimit = 4096 Change Mssql. textlimit = 2147483647 Find:
; Mssql. textsize = 4096 Change
Mssql. textsize = 2147483647
|
2. you can modify fields. since ntext and nvarchar fields in SQL server are stored in unicode encoding,
Therefore, php will read ntext and nvarchar fields through mssql extension.
If the title field type is nvarchar and the content field type is ntext, the following SQL statement reports an error:
Incorrect:
The code is as follows: |
|
Select title, content from article Correct: Select convert (varchar (255), title) as title, Convert (text, content) as content From article
|
3. if you are a VM, you can use the adodb component to read the data. If your host does not support it, I cannot do it now.
The code is as follows: |
|
Include ("adodb/adodb. inc. php"); // contains the adodb class library file $ Conn = NewADOConnection ('odbc _ mssql'); // connect to the SQL Server database $ Conn-> Connect ("Driver = {SQL Server}; Server = localhost; Database = mydb; ", 'username', 'password '); ?>
|
...