tags:

views:

321

answers:

4

Is there a work around (other than changing the column type to a textfield) for SELECTing a large varchar field using PHP and mssql library? For instance a varchar(500). Does PHP really restrict the number of characters to 255? Is there a way to pull back more than that?

A: 

The cause may actually be MySQL rather than PHP... Prior to MySQL 5.0.3 MySQL itself could only store 255 characters in a VARCHAR firled. THis limit has been raised to 65535 in later versions.

Jim OHalloran
Not MySQL, MS SQL. I'm not the one developing this - my team mate is. I'm just asking the question.
Josh Smeaton
Whoops, sorry, my mistake.
Jim OHalloran
+1  A: 

From the PHP page, the problem seems to be the underlying database driver on Windows platforms. Varchar can only return < 255 characters. The work around is to cast the varchar to text within the sql SELECT statement.

Josh Smeaton
A: 

I'm not sure about casting, I'd change the relevant field types to Text instead of Varchar.

PaulBM
That's what we ended up doing - but we weren't sure if that was going to break existing functionality. It didn't. But that's the work around in case you really can't change the type of the field you're working with.
Josh Smeaton
+1  A: 

To cast a wide VARCHAR to TEXT in MS SQL:

SELECT convert(text,myWideField) FROM myTable

Where myWideField is the column being truncated and myTable is well... my table.

The result will be cast to TEXT returning more than 256 chars.

d.

dengel