How to Get the Sqlsrv Extension to Work With PHP, Since Mssql Is Deprecated

How do I get the SQLSRV extension to work with PHP, since MSSQL is deprecated?

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:

  • Loading the Microsoft Drivers for PHP for SQL Server

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)

  • System Requirements (Microsoft Drivers for PHP for SQL Server)
  • Getting Started
  • Programming Guide
  • SQLSRV Driver API Reference (Microsoft Drivers for PHP for SQL Server)

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.

How to get SQLSRV on Xampp working with Medoo?

All information you need are on this this web page https://msdn.microsoft.com/en-us/library/cc296170(v=sql.105).aspx.

As you can see you need version 3.2 for PHP 5.6 support. I found download link and information about adding SQLSRV extension to php.ini for you.

https://www.microsoft.com/en-us/download/details.aspx?id=20098

https://msdn.microsoft.com/en-us/library/cc296203(v=sql.105).aspx

Finally you have to install Microsoft ODBC Driver 11 for SQL Server.

In short, download SQLSRV 3.2, add PDO extension to php.ini (choose right version for your PHP), install Microsoft ODBC Driver 11 for SQL Server on your local enviroment.

mssql_connect no longer working as of PHP 5.3

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

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

Maybe you should look into converting your app to use PDO:
http://www.php.net/manual/en/ref.pdo-sqlsrv.php

Connection between MSSQL and PHP 5.3.5 on IIS is not working

This is a snippet from a customer FAQ I wrote up a wee while ago to help our dedicated hosting customers get PHP up and running with the MS SQL Drivers. It may duplicate some knowledge already imparted in the comments above, but it's completeness may also help others starting from scratch:

Note: Clearly the PHP version numbers have moved on a bit since I wrote this but the general principles still apply.


Installation Pre-requisite:
The SQL Native Client is required for the Microsoft Drivers for PHP for SQL Server:

Microsoft SQL Server 2008 R2 Native Client X64 - for 64 bit Windows

or

Microsoft SQL Server 2008 R2 Native Client X32 - for 32 bit Windows

Download and install the Native Client driver that matches your system.

PHP MS SQL Drivers:

Download the Microsoft Drivers for PHP for SQL Server:

Microsoft Drivers for PHP for SQL Server

The file is a self-extracting executable so just use 7zip or WinRAR and extract the files to a folder of your choice. We now need to decide which driver to choose that matches your PHP installation.

PHP 5.3.5 comes in four different flavours:

  • PHP 5.3.5 Non-threadsafe VC9
  • PHP 5.3.5 Non-threadsafe VC6
  • PHP 5.3.5 Threadsafe VC9
  • PHP 5.3.5 Threadsafe VC6

To tell which version you have installed open the snapshot.txt file which lives in the same folder as php.exe, php-cgi.exe etc. Don't use notepad.exe because the file uses just line feed (\n) for line ends (unix format) at the start and notepad mangles these into a single line.

In the file you will see a line (around line 6, or near the middle of line 1 of you did use notepad) starting with: Build::


Build: D:\php-sdk\snap_5_3\vc9\x86\obj\Release - non-threadsafe, VC9 build
Build: D:\php-sdk\snap_5_3\vc6\x86\obj\Release - non-threadsafe, VC6 build
Build: D:\php-sdk\snap_5_3\vc9\x86\obj\Release_TS - threadsafe, VC9 build
Build: D:\php-sdk\snap_5_3\vc6\x86\obj\Release_TS - threadsafe, VC6 build

This tells us what version of PHP you're running.

From the folder you extracted the MS SQL PHP drivers, choose the driver(s) that matches the version of PHP being used (if you're not using PDO then you don't need to copy the php_pdo_ drivers):


PHP 5.3.5 Non-threadsafe VC9: php_sqlsrv_53_nts_vc9.dll, php_pdo_sqlsrv_53_nts_vc9.dll
PHP 5.3.5 Non-threadsafe VC6: php_sqlsrv_53_nts_vc6.dll, php_pdo_sqlsrv_53_nts_vc6.dll
PHP 5.3.5 Threadsafe VC9: php_sqlsrv_53_ts_vc9.dll, php_pdo_sqlsrv_53_ts_vc9.dll
PHP 5.3.5 Threadsafe VC6: php_sqlsrv_53_ts_vc6.dll, php_pdo_sqlsrv_53_ts_vc6.dll

Assuming your PHP installation lives in C:\PHP, copy (DON'T MOVE) these files to your C:\PHP\EXT folder.

Open C:\PHP\PHP.INI and locate the Dynamic Extensions part of the file and add:


extension=php_sqlsrv_53_nts_vc9.dll
extension=php_pdo_sqlsrv_53_nts_vc9.dll <-- optional

Finally, to be sure that PHP can find these extensions, ensure the extension_dir directive in C:\PHP\PHP.INI is set to C:\PHP\EXT:


extension_dir = C:\PHP\ext

Restart IIS and call phpinfo(). If all is well you should see:

Sample Image

And if you also loaded the PDO driver you should see:

Sample Image



Related Topics



Leave a reply



Submit