search
Homephp教程php手册php读取mssql的ntext字段反回值为空

php读取mssql的ntext字段反回值为空

Jun 13, 2016 am 10:09 AM
mssqlphpforusevalueexistFielddatabasehourofreadconnect

今天在使用php连接mssql数据库时发现ntext字段的内容无法显示,经过查询发现ntext字段在php中不被支持,解决办法我们只要把ntext字段改成text即可解决了。

果是表里面没有ntext字段,可以用以下代码:

 代码如下 复制代码


// 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);
?>

如果表里面有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');
?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft