PHP MS SQL Truncated VarChar(255)

Sharing is Caring

I don’t often have fields much longer than 256 char, but a web application I am working on makes use of varchar 512. I’m not really able to change the field to text as the PHP Docs suggest. MS SQL doesn’t allow the equal operator, and grouping on text fields, and it’s also very slow compared to a varchar which can make advanced queries very difficult. “Due to a limitation in the underlying API used by PHP (MS DBLib C API), the length of VARCHAR fields is limited to 255”

Basically, it appears that PHP is using some old C API from Microsoft and to get around this need to convert from varchar to text. Text by default, allows about 8,000 characters but changing this fairly simple in the php.ini


mssql.textlimit = 65536
mssql.textsize = 65536

Of course, you can also set it dynamically using ini_set.

ini_set("mssql.textlimit", '65536' );
ini_set("mssql.textsize", '65536' );

Hope this helps.

Sharing is Caring

Brian is a programmer and technology leader living in Niagara Falls with more than ten years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.