問題描述
我目前正在嘗試從我們限制從 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 個字符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!