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

后端 未结 4 2016
长发绾君心
长发绾君心 2020-12-19 09:33

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

4条回答
  •  难免孤独
    2020-12-19 10:33

    FreeTDS, by default, uses protocol version 4.2 If you up the protocol to 7.0 you can retrieve more than 255 bytes of a varchar. You can use the "CAST" hack, or you can ALTER COLUMN col varchar(max).

    varchar(max) is a completely different column type than varchar (DATA_TYPE 2005 vs 12) and will be streamed over freetds 4.2 w/o truncating.

    Why not upgrade to version 7? Because UTF-8 cannot be stored in varchar with newer protocols. SQL Server will transmit ALL protocol information in UCS-2 (like UTF-16) and convert your data into the table or column collation before saving. But, this requires you to prefix UTF8 data with N. INSERT into tbl (txt) values (N'hello world')

    Why not CAST? CAST AS TEXT is not compatible with MySQL (need to do CAST AS CHAR).

    Staying on protocol 4.2 and defining your varchars as varchar(max) let's you write the most compatible SQL.

提交回复
热议问题