PHP MS SQL Truncated VarChar(255)

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.

PHP Update Finally Depreciates PHP MSSQL driver

A couple of weeks ago, I noticed there was a new version of PHP out than I was using for my development environment (WAMP) and decided that I should take the time and upgrade the development environment and perhaps even the production environment after retesting my web applications.

The actual upgrade process itself was simple, but PHP 5.3 deprecates the MSSQL Extension. Instead you must now use at least the SQL Server Driver for PHP v1.1 which is of course Windows only and requires any installation of Windows preceding Windows 2000. You need to ensure you have installed the SQL Server 2008 Native Client. Making the change wasn’t overly difficult because I took the upfront time and wrote a very simple Database Access Layer because I assumed something may change in the future (driver, database, etc.)

The biggest advantage of the change is being able to better take advantage of Microsoft SQL Server features that probably made you choose to use SQL Server in the first place.In addition, Microsoft has made the source code available. I’m really excited to hear a new version will be out soon that will allow PHP programmers to use PHP Data Objects (PDO) with SQL Server!

Slider by webdesign