Home  >  Article  >  Backend Development  >  PHP连接MSSQL时nvarchar字段长度被截断为255的解决方法_php技巧

PHP连接MSSQL时nvarchar字段长度被截断为255的解决方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:27:251089browse

本文实例讲述了PHP连接MSSQL时nvarchar字段长度被截断为255的解决方法。分享给大家供大家参考。具体分析如下:

PHP 连接 MSSQL 的新手经常遇到这个问题:数据库里面的 nvarchar 字段中数据一切正常,但是用 PHP 查询出来却发现长度只有 255,我们都知道,在 MySQL 里面 varchar 的长度只有 255,但是 MSSQL 却不是,不会是 PHP 将 nvarchar 按照 MySQL 的 varchar 处理了吧.

本文给出了解决方法:

复制代码 代码如下:
select cast(目标字段 as text) from 表名

假如你的 article 表中有个字段 summary 为 nvarchar,那么命令为:

复制代码 代码如下:
select cast(summary as text) from article

关于 cast,代码如下:

复制代码 代码如下:
CAST ( expression AS data_type )

expression 为目标字段

data_type 为要转换成的数据类型

希望本文所述对大家的php程序设计有所帮助。

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