I'm using FreeTDS / ODBC to connect to an SQLServer2005 database from CentOS7 using PHP. It's working well, except for one field--a large "note" text field that is getting truncated at 4096 characters. How can I get my PHP odbc_exec query to retrieve the entire text field?
I'm in the process of migrating the database from SQLServer2005 to SQLServer2016, but the text field truncating issue seems to behave the same way on both.
I tried setting the textsize within the query itself:
SET TEXTSIZE 2147483647; SELECT note FROM soap WHERE organizationId=41 and patientId=2019 AND noteId=189
I have tested the above connection & query in isql with my odbc/freetds settings & it does seem to retrieve the entire text field correctly. Here is part of the output from my freetds.log:
17:30:50.367355 29543 (token.c:1542):tds7_get_data_info:
colname = note
type = 35 (text)
server's type = 35 (text)
column_varint_size = 4
column_size = 2147483647 (2147483647 on server)
I have tried setting the text size in the odbc.ini file:
[ClaimsServiceNewTest]
Driver = /usr/lib64/libtdsodbc.so.0
Description = Advanced Billing Service Database (TESTING OLD SQL)
Trace = Yes
TraceFile =/tmp/sql.log
ForceTrace = Yes
SERVERNAME = ClaimsServiceNewTest
User = ********
Password = ********
Database = ********
Port = 1433
TDS_Version = 7.1
TextSize = 2147483647
I have also set the text size in the freetds.conf file:
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 4294967295
It is only when I try to run the query in my PHP script that it get's truncated.
Any suggestions? I am fairly new to all of this, so please let me know if I'm missing something obvious. I also noticed that isql is outputting a TDSDUMP to my freetds.log file, but my PHP queries are not--I don't know if this is expected behavior, but if you have suggestions on outputting TDSDUMP from my PHP queries, I imagine that it would have additional useful info.
Thanks for the consideration!
EDIT: One great suggestion by Mark Thomas was to change the mssql.textlimit and mssql.textsize in php.ini. I've changed this in the php.ini file (and also done it in-script with: ini_set('mssql.textlimit', 10000000); , but I don't see that it has made a difference (restarting apache after changes to php.ini should be sufficient, right?).
odbc_binmode(..., ODBC_BINMODE_RETURN). That fixed the problem for me when using another DBMS (Oracle).cast( varchar(max), note ) as notein place of note in your query.