php读取字段类型为ntext时出错
代码如下:<?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 fromT_News order by Id desc';
// $sql='select top 10 Second_Title,convert(varchar,Contents) as content fromT_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 fromT_News order by Id desc';
就行了
页:
[1]