代码如下:
<?php
$host="CHENGXIANJU";
$user='sa';
$password='01211107';
$database='copy0551fcdbs';
$link=mssql_connect($host,$user,$password);
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
mssql_select_db('copy0551fcdbs', $link);
$sql='select top 10 Second_Title,Contents from T_News order by Id desc';
// $sql='select top 10 Second_Title,convert(varchar,Contents) as content from T_News order by Id desc';
$rs=mssql_query($sql);
while($row=mssql_fetch_array($rs)){
print_r($row);
}
提示如下错误:
Warning: mssql_query() [function.mssql-query ]: message: 不能用 DB-Library (如 ISQL)或 ODBC 3.7 或更早版本将 ntext 数据或仅使用 Unicode 排序规则的 Unicode 数据发送到客户端。 (severity 16) in D:\php5\sqlserver.php on line 13
这是由于:
由于sql server中,ntext和nvarchar字段是用unicode编码存储内容的,因此php通过mssql扩展读取带ntext和nvarchar类型字段的时候会抱错。
字段Contents是ntext类型,所以会出错
改成
$sql='select top 10 Second_Title,convert(varchar,Contents) as content from T_News order by Id desc';
就行了
解决PHP读取SQL Server NTEXT字段问题
本文介绍了一种解决PHP通过MSSQL扩展读取SQL Server中NTTEXT和NVARCHAR类型字段时出现的错误的方法。通过将字段转换为VARCHAR类型,成功避免了因Unicode编码引起的错误。
868

被折叠的 条评论
为什么被折叠?



