Home > PHP, SQL Server > Microsoft (SQL Server 2.0) Drivers for PHP!! using SQLSRV

Microsoft (SQL Server 2.0) Drivers for PHP!! using SQLSRV

1. First we need to install SQL Server Native Client before installing SQL driver for PHP  in your System.
My System Configuration is,
Operating System: Windows 7
System Type: 32-bit Operating System

Install from the http://technet.microsoft.com/en-us/library/cc296170.aspx

— We will get a page titles System Requirements
— We can see a link “Download the X86 package” (If 64-bit OS download X64 package)
— Click the link will download the required file.
— Install it into our system.

2. Download SQLSRV30.EXE OR SQLSRV20.EXE  from http://www.microsoft.com/download/en/details.aspx?id=17308
as per our system requirements.
Check php.ini – If

Compiler MSVC9 (Visual C++ 2008)

Then download php_sqlsrv_53_ts_vc9.dll and include in php.ini as STEP 5.

3.Run the SQLSRV30.EXE OR SQLSRV20.EXE file will ask path for placing the files. Select the PHP extension Directory.
Ex: D:\wamp\bin\php\php5.3.8\ext

4. Also check in php.ini
extension_dir = “D:/wamp/bin/php/php5.3.8/ext/”

5. Include in php.ini as,




See the configuration of your system and enable it in php.ini

6. Restart the wampp Server. If not reflected in phpinfo(), restart the sytem.

PHP Code to Connect

<?php//phpinfo();/*Connect to the local server using Windows Authentication and specifythe AdventureWorks database as the database in use. To connect usingSQL Server Authentication, set values for the “UID” and “PWD”attributes in the $connectionInfo parameter. For example:$connectionInfo = array(“UID” => $uid, “PWD” => $pwd, “Database”=>”AdventureWorks”);*/$serverName = “\SQL2000”;

$connectionInfo = array( “Database”=>”MCMS”, “UID”=>”sa”, “PWD”=>”Defiance123”);

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )


//echo “Connection established.\n”;

/* Get the product picture for a given product ID. */

$tsql = “SELECT  [BlobData] FROM [MCMS].[dbo].[BlobTable] WHERE BlobId = ?”;

$params = array(24);

/* Execute the query. */

$stmt = sqlsrv_query($conn, $tsql, $params);

if( $stmt === false )


echo “Error in statement execution.</br>”;

die( print_r( sqlsrv_errors(), true));


/* Retrieve the image as a binary stream. */


if ( sqlsrv_fetch( $stmt ) )


$image = sqlsrv_get_field( $stmt, 0, $getAsType);





echo “Error in retrieving data.</br>”;

die(print_r( sqlsrv_errors(), true));


/* Free the statement and connectin resources. */

sqlsrv_free_stmt( $stmt );

sqlsrv_close( $conn );




echo “Connection could not be established.\n”;

die( print_r( sqlsrv_errors(), true));



Categories: PHP, SQL Server
  1. Yoel Villarreal Davila
    April 2, 2012 at 9:17 PM

    This driver applies only to IIS or is it possible to load it from apache too???

    • Kanchana Rajasekaran
      April 3, 2012 at 10:25 AM

      I have configured with wamp only (PHP, Apache, SQL SERVER)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: