A search for "SQL Server Driver for PHP" gave no results, and I decided to write this article.
Some already know that Microsoft have released their driver for PHP with blackjack using the capabilities of the Native SQL Client, and even opened the source code .
Why is it needed?
First, the standard MS SQL driver (php_mssql.dll), which comes bundled with PHP, has several disadvantages. The main thing is that it is based on the ntwdblib.dll library, which is no longer supported by Microsoft, and is no longer included with the new versions of MS SQL Server. The latest version has the following problems:
The limit on the maximum field length in a resultset is 255 characters;
The limit on the maximum length of a variable when calling a stored procedure is the same 255 characters;
The problem with empty strings when calling a stored procedure; If you call a stored procedure, where the parameter is an empty string, the library will magically turn the string into NULL.
The problem with the type of varchar and nvarchar dimension more than 255 characters; Anything longer is simply clipped.A workaround is to cast the field type to varchar (max).In this case, everything works correctly.
Also, ntwdblib.dll is significantly inferior in speed of obtaining results of the Native SQL Client.
All of the above problems are solved using the “SQL Server Driver for PHP”. However, we gain new problems:
The absence (possibly temporarily) of several very useful functions-analogues of the old MSSQL driver; For example, getting the number of rows changed, and, until recently, there was no function to get the number of rows in a resultset.
Problems with getting the returned result from the stored procedure when a multiple resultset is returned, even if they are empty; This, of course, can be circumvented by setting the NOCOUNT flag to ON by calling SET NOCOUNT ON before the request, but this is not the most beautiful solution.
When a deadlock occurs, the new driver does not have a convenient mechanism for bypassing this situation; A workaround is to use the PHP sleep () or usleep () function and, if a lock occurs, try the query again in a couple of seconds.
When receiving results, the new driver converts data from the database type to its counterpart in PHP, although this is correct in terms of data typing; So, for example, a field with a datetime type will be converted to a PHP type DateTime, and binary and text fields to a PHP Stream, which is not convenient, becauseit is necessary to further process the results obtained in order to obtain the final result that interests us.
Total lack of support under * nix systems While php_mssql can be compiled using FreeTDS.
Perhaps the most serious drawback is not always stable work under <irony> IIS6 </ irony>, under IIS7 and Apache such problems were not noticed.
Despite such a large enough list of new problems, it makes sense to look at the Microsoft driver and examine its work in their projects under Windows Server and MS SQL. The project is developing steadily and problems are eliminated. ')
I hope this review is useful to someone.