0

I am executing a SQL query inside a PHP script. The query is executed against a SQL Server database, using the PDO class. I am retrieving the results of the query using $result->fetch(PDO::FETCH_ASSOC).

One of the columns in the result is a string that could be in excess of 256 characters, but when I access this value in PHP, the string is always truncated at 256 characters. The value itself is basically just a sentence i.e., reasonable for its length to exceed 256 characters, but not 1024 characters.

The MS SQL DB stores the data in (effectively) a VARCHAR(1024) column. If I run the query in Visual Studio, there is no truncation - I get the full string returned.

I can obviously modify the query and the PHP code (not the configuration), but not the MS SQL DB.

Where is the truncation happening? How do I retrieve the full string in my PHP code?

2
  • please add some code in question Commented Mar 12, 2016 at 14:58
  • thank you for your time - stumbled on a solution (below) Commented Mar 12, 2016 at 15:30

1 Answer 1

1

I tried a few things and found something that worked.

In the MS SQL query, I wrapped the offending field in a CAST(x as TEXT). This seems to have done the trick.

As a record of some of the other things I tried:

The comments on this page make reference to retrieving large strings. http://php.net/manual/en/function.mssql-query.php

The suggestions are to execute these lines as part of the PHP script:

$conn->query('SET TEXTSIZE 2147483647');
ini_set ( 'mssql.textlimit' , '2147483647' );
ini_set ( 'mssql.textsize' , '2147483647' );

Some people seem to say that the query alone works; others say that the php ini lines did the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.