MS SQL Server上的ODBC查询仅在PHP PDO(FreeTDS)中返回前255个字符 [英] ODBC query on MS SQL Server returning first 255 characters only in PHP PDO (FreeTDS)

查看:47
本文介绍了MS SQL Server上的ODBC查询仅在PHP PDO(FreeTDS)中返回前255个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正试图从SQL Server数据库视图中提取某些数据,但我们限制了从Linux Web服务器对其的访问.

I'm currently trying to pull some data from a SQL Server database view that we have restricted access to from our Linux web server.

我们不需要编辑数据,只需将其显示在网页中即可.

We don't need to edit the data just display it in a webpage.

在我们尝试输出并只获得文本字段的前255个字符之前,一切看起来都很好.

It all looks fine until we try to output and only get the first 255 characters of a text field.

有人知道通过PHP :: PDO使用FreeTDS是否存在问题,或者是否可以正常工作?我见过其他人也有类似的问题,但似乎没有很多答案.

Does anyone know if this is a problem with using FreeTDS through PHP::PDO or if it should work fine? I've seen other people out there having similar problems, but there don't seem to be many answers.

我正在使用它作为MS SQL数据库的连接字符串:

I'm using this as the connection string for the MS SQL db:

$dbConn = new PDO("odbc:Driver=FreeTDS;DSN=OURDSN;UID=WWWUser;PWD=ourpassword");

推荐答案

根据 FreeTDS用户指南,问题似乎是,由于协议定义固有的局限性,与SQL Server 通话时,FreeTDS最多只能处理varchar个255个字符.大于此值的任何数据都必须为数据类型text.

According to the FreeTDS User Guide, the issue seems to be that FreeTDS can only handle varchar up to 255 characters when talking to SQL Server "due to limitations inherent in the protocol definition". Anything bigger than that needs to be data type text.

您可以通过相应地修改架构或在查询期间转换数据类型来解决此问题,如下所示:

You can resolve the issue either by modifying your schema accordingly, or converting the data type during your query, like this:

SELECT CAST(mycol as TEXT) FROM mytable

这篇关于MS SQL Server上的ODBC查询仅在PHP PDO(FreeTDS)中返回前255个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆