我目前正在尝试从我们限制从 Linux Web 服务器访问的 SQL Server 数据库视图中提取一些数据.
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 用户指南,问题似乎是 FreeTDS 在与 SQL Server 交谈时只能处理 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 个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!