Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can PHP and mssql library select more than 256 characters from a varchar column?

Tags:

php

sql-server

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?

like image 996
Josh Smeaton Avatar asked Mar 04 '09 05:03

Josh Smeaton


3 Answers

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.

like image 113
Josh Smeaton Avatar answered Sep 28 '22 03:09

Josh Smeaton


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.

like image 21
dengel Avatar answered Sep 28 '22 04:09

dengel


Try to change the freetds configuration.

In the server, edit /etc/freetds.conf

Change:

tds version = 4.2

to:

tds version = 8.0

See more in User Contributed Notes, Mssql Functions Reference.

like image 29
edercortes Avatar answered Sep 28 '22 03:09

edercortes