After a long time today, we can clearly link to the database, but cannot read data. Google and Baidu finally learned that the reverse return value of the ntext field of mssql read by php is null. we recommend that you change the ntext field to text.
The reason may be: php's support for the ntext type of mssql;
After a long time today, we can clearly link to the database, but cannot read data. Google and Baidu finally learned that the reverse return value of the ntext field of mssql read by php is null. we recommend that you change the ntext field to text.
If there is no ntext field in the table, use the following code:
// Connect to MSSQL $ Link = mssql_connect ('kallespc \ SQLEXPRESS ', 'sa', 'phpfi ');
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:
; Mssql. textlimit = 4096 |
Change
Mssql. textlimit = 2147483647 |
Find:
Change
Mssql. textsize = 2147483647 |
2. you can modify fieldsIn SQL server, ntext and nvarchar fields are stored in unicode encoding. Therefore, php uses mssql extension to read ntext and nvarchar fields with errors.
If the title field type is nvarchar and the content field type is ntext, the following SQL statement reports an error:
Incorrect:
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. If your host does not support it, I cannot do it now.
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 '); ?>
|