Export (0) Print
Expand All

Loading the Microsoft Drivers for PHP for SQL Server

SQL Server 2008 R2

This topic provides instructions for loading the Microsoft Drivers for PHP for SQL Server into the PHP process space.

There are two options for loading a driver. The driver can be loaded when PHP is started or it can be loaded at PHP script runtime.

Regardless of which procedure you use, the first step will be to put the driver file in a directory where the PHP runtime can find it. So, put the driver file in your PHP extension directory. See System Requirements for a list of the driver files that are installed with the Microsoft Drivers for PHP for SQL Server.

If necessary, specify the directory location of the driver file in the PHP configuration file (php.ini), using the extension_dir option. For example, if you will put the driver file in your c:\php\ext directory, use this option:

extension_dir = "c:\PHP\ext"

To load the Microsoft Drivers for PHP for SQL Server when PHP is started, first move a driver file into your extension directory. Then, follow these steps:

  1. To enable the SQLSRV driver, modify php.ini by adding the following line to the extension section, or modifying the line that is already there (this example uses the version 3.1 thread safe driver for PHP 5.4):

    extension=php_sqlsrv_54_ts.dll
    

    To enable the PDO_SQLSRV driver, modify php.ini by adding the following line to the extension section, or modifying the line that is already there (this example uses the version 3.1 thread safe driver for PHP 5.4):

    extension=php_pdo_sqlsrv_54_ts.dll
    
  2. If you want to use the PDO_SQLSRV driver, the php_pdo.dll must be available, either as a built-in extension, or as a dynamically-loaded extension. If you need to load the PDO_SQLSRV driver dynamically, the php_pdo.dll must be present in the extension directory and the the following line needs to be in the php.ini:

    extension=php_pdo.dll
    
  3. Restart the Web server.

Note Note

To determine whether the driver has been successfully loaded, run a script that calls phpinfo().

For more information about php.ini directives, see Description of core php.ini directives.

To load the Microsoft Drivers for PHP for SQL Server at script runtime, first move a driver file into your extension directory. Then include the following line at the start of the PHP script that will use the driver:

dl('php_pdo_sqlsrv_54_ts.dll');

For more information about PHP functions related to dynamically loading extensions, see dl and extension_loaded.

Community Additions

ADD
Show:
© 2014 Microsoft