PHP教程:PHP不能读取MS SQL数据表
原因可能是:php对mssql的ntext类型的支持问题;
今天弄了半天,明明可以链接到数据库,却不能读取的数据。Google,百度一番之后终于知道了,原来是php读取mssql的 ntext字段反回值为空的,建议可以把ntext字段改成 text。
如果是表里面没有ntext字段,可以用以下代码:
// 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 of // MSSQL and print it. $version = mssql_query('SELECT @@VERSION'); $row = mssql_fetch_array($version); echo $row[0]; // Clean up mssql_free_result($version); ?> |
如果表里面有ntext军字段,且不好修改回text字段, 可以如下:
1.修改 php.ini
打开php.ini
找到:
;mssql.textlimit = 4096 |
改为
mssql.textlimit = 2147483647 |
找到:
;mssql.textsize = 4096 |
改为
mssql.textsize = 2147483647 |
2.可以使用修改字段,由于sql server中,ntext和nvarchar字段是用unicode编码存储内容的,因此php通过mssql扩展读取带ntext和nvarchar类型字段的时候会抱错。
如果 title 字段类型为 nvarchar,content 字段类型为 ntext ,那么下面的sql语句会报错:
错的:
select title,content from article |
正确的:
select convert(varchar(255),title) as title, convert(text,content) as content from article |
3.如果你是虚拟主机,可以使用adodb 组件来读取。如果你主机不支持,目前笔者也没办法了。
include("adodb/adodb.inc.php"); //包含adodb类库文件 $conn=NewADOConnection('odbc_mssql'); //连接SQL Server数据库 $conn->Connect("Driver={SQL Server};Server=localhost;Database=mydb;",'username','password'); ?> |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
