ODBC query on MS SQL Server returning the first 255 characters only in PHP PDO (FreeTDS)

I am currently trying to extract some data from a SQL Server database view with which we have restricted access from our Linux web server.

We do not need to edit the data by simply displaying it on a web page.

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

Does anyone know if this is a problem using FreeTDS via PHP :: PDO or if it should work fine? I have seen other people face similar problems, but there are not many answers.

I use this as a connection string for MS SQL db:

$dbConn = new PDO("odbc:Driver=FreeTDS;DSN=OURDSN;UID=WWWUser;PWD=ourpassword");
+5
source share
4 answers

According to the FreeTDS User Guide, the problem is that FreeTDS can only process varcharup to 255 characters when talking to SQL Server "because of the limitations inherent in the protocol definition." All that should be more should be a data type text.

You can solve the problem either by changing your schema accordingly, or by converting the data type during the request, for example:

SELECT CAST(mycol as TEXT) FROM mytable
+5
source

You can increase the size of the text fields in the /etc/odbc.ini file used by FreeTDS.

[name_of_connection]
TextSize = 2097152

You can also try using the low-level odbc routines in PHP to make sure you can get this level of data retrieval and then revert to using PDO.

+1

FreeTDS, , 4.2. 7.0, 255 varchar. "CAST", ALTER COLUMN col varchar (max).

varchar (max) - , varchar (DATA_TYPE 2005 12) freetds 4.2 .

7? UTF-8 varchar . SQL Server UCS-2 (, UTF-16) . UTF8 N. INSERT tbl (txt) ( N'hello)

CAST? CAST AS TEXT MySQL ( CAST AS CHAR).

4.2 varchars varchar (max), SQL.

+1

. 2015 , XML , 25 6 . , XML . , , 256.

XML ( FOR XML) - . , , CAST-, varchar (max).

, : 256 , , , , XML, XML, varchar (max).

CAVEAT: , XML .

0

All Articles