3

I have a MS SQL query that is selecting a field and it is being chopped off for some reason it is cutting off text at 257 characters.

Is there some kind of default cut-off for retrieving results with MSSQL and PHP?

I'm honestly clueless as to why this is happening. ANY guidance would be greatly appreciated

The field type is "char"

Here is a screen shot of my MS SQL config from phpinfo() alt text http://www.aaacoloautosource.com/mssql_config.png

could it be the mssql.textlimit or mssql.textsize value?

4
  • The field type is "char" Commented Jun 2, 2010 at 16:48
  • How big can a char field be? Is it char(255) or something? The number 257 is suspiciously close to 256 == 2^8 Commented Jun 2, 2010 at 16:59
  • Can the field in the DB store more than 257 characters? Commented Jun 2, 2010 at 17:00
  • yes, the DB is storing more than 257 characters Commented Jun 2, 2010 at 18:03

3 Answers 3

2

Somehow the datatype is "char", which apparently is limited to 255 characters. BUT the DB is storing more than 255 characters.

Converting the field to TEXT works perfectly for some reason.

SELECT CONVERT(TEXT,fld_name) FROM TABLE_NAME

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

Comments

1

The problem is most likely that you are using TDS protocol version 4.2. You should upgrade to at least 7.0 by setting this in /etc/freetds.conf:

tds version = 7.0

The limitations of version 4.2 are:

  • ASCII only
  • RPC is not supported.
  • BCP is not supported.
  • varchar fields are limited to 255 characters. If your table defines longer fields, they'll be truncated.
  • dynamic queries (also called prepared statements) are not supported.

For more details, see http://freetds.schemamania.org/userguide/choosingtdsprotocol.htm

Comments

-1

From the mysql manual:

The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255.

In my version of MYSQL, I cannot set a char field to longer than 255 characters, as per the above specification.

Is there any reason you need to use char? Try using text or blob or varchar instead.

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.