需求

Requirements for Win32 platforms.

The extension requires the MS SQL Client Tools to be installed on the system where PHP is installed. The Client Tools can be installed from the MS SQL Server CD or by copying ntwdblib.dll from \winnt\system32 on the server to \winnt\system32 on the PHP box. Copying ntwdblib.dll will only provide access through named pipes. Configuration of the client will require installation of all the tools.

This extension is not available anymore on Windows with PHP 5.3 or later.

SqlSrv, an alternative driver for MS SQL is available from Microsoft: » http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx.

Requirements for Unix/Linux platforms.

To use the MSSQL extension on Unix/Linux, you first need to build and install the FreeTDS library. Source code and installation instructions are available at the FreeTDS home page: » http://www.freetds.org/

Note:

On Windows, the DBLIB from Microsoft is used. Functions that return a column name are based on the dbcolname() function in DBLIB. DBLIB was developed for SQL Server 6.x where the max identifier length is 30. For this reason, the maximum column length is 30 characters. On platforms where FreeTDS is used (Linux), this is not a problem.

Note:

On Windows, if you're using MSSQL 2005 or greater you must copy the ntwdblib.dll into the directory where you have installed php and overwrite the one thats already in there. This is due to the version distributed is old and outdated. Alternatively you can use the » http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx, ODBC, PDO_DBLIB or PDO_ODBC extensions, to talk to MSSQL.

User Contributed Notes

gustavo dot beavis at gmail dot com 30-Oct-2015 12:53
I had problems with freeTDS version 4.2, and I believe that versions prior to 7.0 have this limit of 30 characters per fields.

I solved the problem by changing to version 8.0
mihabo at hotmail dot com 03-Mar-2010 12:56
I have struggled a lot to make PHP connect to a MS SQL server from under a Linux (using FreeTDS).
I installed the latest FreeTDS and tried to use usual host:port to connect to a server.
Finally when I configured freetds.conf like that:

[mysrvalias]
        host = 192.168.17.17
        port = 1433
        tds version = 7.0

and used mysrvalias instead of the 192.168.17.17:1433, it worked!