How To Install PHP MSSQL extension

Microsoft did away with the PHP MSSQL extension actually being called MSSQL. They renamed it to SQLSRV.

Install PHP (http://www.microsoft.com/web/platform/phponwindows.aspx)

Run the executables for SQLSRV (http://www.microsoft.com/en-us/download/details.aspx?id=20098)

Place the library files into the PHP/v5.x folder. (Example: php_sqlsrv_52_nts_vc6.dll)

Edit the php.ini file (C:/Program Files/PHP/v5.x/)

Add to the bottom of the file…
extension=php_pdo_sqlsrv.dll
extension=php_sqlsrv.dll

In administrative Tools > Services : Restart IIS.

Create a PHP file to check the PHP settings…

phpinfo();

You should see this line…

sqlsrv
Here’s a good example of some MSSQL code you can test with…

$serverName = "SERVER\SQLEXPRESS";
$connectionOptions = array("Database"=>"DBNAME", "UID"=>"USERNAME", "PWD"=>"PASSHERE");
$conn = sqlsrv_connect( $serverName, $connectionOptions);
if (!$conn) {
die( print_r( sqlsrv_errors(), true));
}
$query = sqlsrv_query($conn, "SELECT * FROM Job WHERE Job = '84327'") or die(print_r(sqlsrv_errors()));
while($row = sqlsrv_fetch_array( $query, SQLSRV_FETCH_ASSOC )) {
echo $row['Part_Number'];
}

2 comments

  1. Thank for sharing it, It’s informative for me. Although , I got it when I try

    Array
    (
    [0] => Array
    (
    [0] => IMSSP
    [SQLSTATE] => IMSSP
    [1] => -49
    [code] => -49
    [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
    [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
    )

    [1] => Array
    (
    [0] => IM002
    [SQLSTATE] => IM002
    [1] => 0
    [code] => 0
    [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    )

    )

Comments are closed.