27

I upgraded to PHP 5.3, and noticed that php_mssql.dll is missing. After googling a bit, it seems that 5.3 has dropped support for mssql. So I downloaded the drivers from microsoft, but I can't seem to get it to work.

I am on windows. What do I need to do, after I unzip the files in the ext directory of my PHP 5.3?

0

3 Answers 3

38

Quoting http://php.net/manual/en/intro.mssql.php:

The MSSQL 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.

Once you downloaded that, follow the instructions at this page:

In a nutshell:

Put the driver file in your PHP extension directory.
Modify the php.ini file to include the driver. For example:

extension=php_sqlsrv_53_nts_vc9.dll  

Restart the Web server.

See Also (copied from that page)

The PHP Manual for the SQLSRV extension is located at http://php.net/manual/en/sqlsrv.installation.php and offers the following for Installation:

The SQLSRV extension is enabled by adding appropriate DLL file to your PHP extension directory and the corresponding entry to the php.ini file. The SQLSRV download comes with several driver files. Which driver file you use will depend on 3 factors: the PHP version you are using, whether you are using thread-safe or non-thread-safe PHP, and whether your PHP installation was compiled with the VC6 or VC9 compiler. For example, if you are running PHP 5.3, you are using non-thread-safe PHP, and your PHP installation was compiled with the VC9 compiler, you should use the php_sqlsrv_53_nts_vc9.dll file. (You should use a non-thread-safe version compiled with the VC9 compiler if you are using IIS as your web server). If you are running PHP 5.2, you are using thread-safe PHP, and your PHP installation was compiled with the VC6 compiler, you should use the php_sqlsrv_52_ts_vc6.dll file.

The drivers can also be used with PDO.

3
  • 1
    okay, got it working. Looks like they have renamed all the functions :( Do I need to use different function calls for windows and linux? Like the old mssql_* for linux, and sqlsrv_* for windows?
    – user187809
    Sep 13, 2011 at 13:50
  • @user187809 The SQLSRV extension is only compatible with PHP running on Windows.
    – Gordon
    Sep 13, 2011 at 14:29
  • can't we use mssql_connect and other mssql_(x) functions in SQLSRV extension? because i have already developed a application with PHP4 and we upgraded to PHP 5.3.x Version.
    – Prabu
    Feb 6, 2013 at 6:39
5

Download Microsoft Drivers for PHP for SQL Server. Extract the files and use one of:

File                             Thread Safe         VC Bulid
php_sqlsrv_53_nts_vc6.dll           No                  VC6
php_sqlsrv_53_nts_vc9.dll           No                  VC9
php_sqlsrv_53_ts_vc6.dll            Yes                 VC6
php_sqlsrv_53_ts_vc9.dll            Yes                 VC9

You can see the Thread Safety status in phpinfo().

Add the correct file to your ext directory and the following line to your php.ini:

extension=php_sqlsrv_53_*_vc*.dll

Use the filename of the file you used.

As Gordon already posted this is the new Extension from Microsoft and uses the sqlsrv_* API instead of mssql_*

Update:
On Linux you do not have the requisite drivers and neither the SQLSERV Extension.
Look at Connect to MS SQL Server from PHP on Linux? for a discussion on this.

In short you need to install FreeTDS and YES you need to use mssql_* functions on linux. see update 2

To simplify things in the long run I would recommend creating a wrapper class with requisite functions which use the appropriate API (sqlsrv_* or mssql_*) based on which extension is loaded.

Update 2: You do not need to use mssql_* functions on linux. You can connect to an ms sql server using PDO + ODBC + FreeTDS. On windows, the best performing method to connect is via PDO + ODBC + SQL Native Client since the PDO + SQLSRV driver can be incredibly slow.

2
  • 1
    What about Linux and Windows? Do I need to use different function calls for different OS?
    – user187809
    Sep 13, 2011 at 13:52
  • 1
    The SQLSRV Extension from microsoft is only available for windows. For using a MS SQL Server from a Linux Web Server you need to use a third party driver as Microsoft doesnt provide one. Look at this question stackoverflow.com/questions/507479/….
    – danishgoel
    Sep 13, 2011 at 14:08
0

Make sure to download the SQL driver here https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15

Then move in the two files with the same version as your php version. (check php -v)

In my case I was using version 7.4.30 and moved the php_pdo_sqlsrv_74_nts_x64.dll and php_sqlsrv_74_nts_x64.dll into my php folder ext

C:\Program Files\php7.4.30\ext

Then open your php.ini file and add the extensions, remember to include ".dll " on the extensions.

extension=php_pdo_sqlsrv_74_nts_x64.dll
extension=php_sqlsrv_74_nts_x64.dll

If you still have problems go to extension dir = "ext" in php.ini and replace ext with the exact path to your ext folder like this:

extension_dir = "C:\Program Files\php7.4.30\ext\"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.