Friday, 7 September 2012

How to install Microsoft's SQL Server Driver for PHP

There are questions on Microsoft's SQL Server driver for PHP forum from people that cannot work out how to install the PHP driver.

PHP offers some help on choosing extensions here:, and here:

It's still a bit complicated, so here are some explicit instructions which I hope can help new users of PHP.  After a while all of this will become common sense.

Instruction notes:
  1. Microsoft's PHP driver for SQL Server only runs with PHP 32-bit builds (as standard from
  2. These instructions are only for PHP 5.2, 5.3 or 5.4. (5.5 and 5.6 supported with custom build.)
  3. I am pretending that PHP is installed into folder C:\PHP.  Replace the term C:\PHP in the instructions with whatever folder your PHP is installed into.
  4. See orange text for PHP 5.5 and 5.6 support in 32 and 64 bits.  If you do not know whether you have 64-bit PHP 5.5/5.6, start the instructions at step 5, note the orange comment in 5.3, then return to step 1 of the instructions below.
  1. Download Microsoft's PHP drivers.  Open page:
    1. If you have Windows Vista, Server 2008 or above, download SQLSRV30.EXE.
    2. If you have Server 2003/Windows XP or below, download SQLSRV20.EXE
    3. If you have PHP 5.5/5.6, or you have Windows XP/2003 and you want to install driver 3.0...
      1. See this post: Unofficial php_sqlsrv 3.0 and download the archive
      2. Note the text in orange in step (2.) below - you don't need to extract the 'source code' folder.  Also...
        1. If you have 64-bit PHP, you need to extract only the files in sub-folder x64 of the zip file, and can ignore everything else.
        2. If you have 32-bit PHP, you should ignore the folder x64 in the zip file.
      3. Assume for step (6.) below that you downloaded SQLSRV30.EXE
      4. Remember that PHP 5.5+ does not work on Windows XP/2003 - for this OS you can only go up to PHP 5.4.
  2. Extract the entire contents of the file downloaded in (1.) to your PHP extensions folder.  This is usually a sub-folder of the location where php is installed, named 'ext', e.g. C:\PHP\ext.
    Note that you can use WinRAR to open the .exe file and extract the files, if you want.

    For users of the Unofficial php_sqlsrv 3.0 zip file:
    1. If you have 64-bit PHP, please extract only the contents of folder x64 of the zip file.
    2. If you have 32-bit PHP, extract the files in the root of the zip and ignore any folders. 
  3. Download the SQL Server Native Client (SNAC), the PHP driver depends on it:
    1. For SQLSRV30.EXE (Windows Vista and above), go here:  These are direct links:
      1. SQL Server 2012 Native Client for 64 Bit Windows (x64)
      2. SQL Server 2012 Native Client for 32 Bit Windows (x86)
    2. For SQLSRV20.EXE (Windows XP/2003), go here:  Here are the direct links:
      1. SQL Server 2008r2 Native Client for 64 Bit Windows (x64)
      2. SQL Server 2008r2 Native Client for 32 Bit Windows (x86)
  4. Install the SQL Server Native Client downloaded from the previous step (3.) on the same computer that runs PHP.
  5. Find out which version of PHP you have (if you already know it, go to step 6):

    1. Open a command window (run cmd.exe)
    2. Using your PHP folder, run command: "C:\PHP\php.exe" -i | more
      'more' loads the information page by page.
    3. The top line will show PHP Version => 5.x.x...  Make a note of the version.  It will start with 5.6, 5.5, 5.4, 5.3 or 5.2.  The final (3rd) number is not important.PHP 5.5+ users can also tell if they have a 64-bit or 32-bit version of PHP by looking at the reported Architecturex86 = 32-bit and x64 = 64-bit.For the next steps you may need to scroll to the 2nd information page in the console window, by pressing the space bar...
    4. For version 5.6, 5.5, 5.4 and 5.3, a little further down is setting PHP Extension Build => API... It will end with either ...TS,VCn or ...NTS,VCn.  Make a note of whether it says TS or NTS.  Also make a note of whether the final part is VC11, VC9 or VC6 (VC6 is still possible with PHP 5.3 and SQLSRV20.EXE).
    5. For PHP version 5.2 only: note the setting that says "Thread Safety enabled" or "Thread Safety disabled". 
      "Thread Safety enabled" means TS,VC6
      "Thread Safety disabled" means NTS,VC6.
  6. Edit your php configuration file, php.ini.  Go to the end of the file and add these lines, depending on your earlier choices.  You need to know your PHP version number (5.2, 5.3, 5.4, 5.5 or 5.6), and your TS/NTS setting, and whether you have a VC11, VC9 or VC6 build, all noted from step 5. above.

    You can calculate the files you need by looking at the file name and comparing to your PHP version, and remembering whether you downloaded SQLSRV20.exe or SQLSRV30.exe.  Here are all of the combinations that are possible:

    • For the custom drivers, PHP 5.6, NTS, VC11 add lines:
    • For the custom drivers, PHP 5.6, TS, VC11 add lines:
    • For the custom drivers, PHP 5.5, NTS, VC11 add lines:
    • For the custom drivers, PHP 5.5, TS, VC11 add lines:
    • For SQLSRV30.EXE (or the custom drivers), PHP 5.4, NTS, VC9 add lines:
    • For SQLSRV30.EXE (or the custom drivers), PHP 5.4, TS, VC9 add lines:
    • For SQLSRV30.EXE (or the custom drivers), PHP 5.3, NTS, VC9 add lines:
    • For SQLSRV30.EXE (or the custom drivers), PHP 5.3, TS, VC9 add lines:
    • For SQLSRV20.EXE, PHP 5.3, NTS, VC9 add lines:
    • For SQLSRV20.EXE, PHP 5.3, NTS, VC6 add lines:
    • For SQLSRV20.EXE, PHP 5.3, TS, VC9 add lines:
    • For SQLSRV20.EXE, PHP 5.3, TS, VC6 add lines:
    • For SQLSRV20.EXE, PHP 5.2, NTS, VC6 add lines:
    • For SQLSRV20.EXE, PHP 5.2, TS, VC6 add lines:
  7. Restart your web server for the change to take effect.  That means stop and start IIS, Apache, or whatever you use, not the whole computer.


  1. Regarding Step 6. Is there no combination that will work for Server 2003/IIS6 (SQLSRV20.EXE) and PHP 5.4.x?

    1. Hi Bryan

      If you go back to step 1.3 (orange writing), you can use a custom build of driver version 3.0 with PHP 5.4 and Windows 2003. It's the only way for that combination - it should work fine as long as you stick to the printed functionality from SQLSRV20.EXE. I just changed a couple of lines so that it used the ODBC driver for 2008 R2 instead of 2012 (which only supports Win Vista+).

  2. Thank you so much.. It works! :)

  3. Hi Rob!! I did everything you said, but still cant have my connection working!!!! I have wamp server 32 bits running on 64 bits windows 7, I got this information from the php.exe
    PHP 5.4, TS, VC9 so i added the lines you told me to add!! I have this code as well

    echo "got server name";
    //connect to DB
    echo "got db name";
    echo "got connection";
    echo "Connection established.
    echo "Connection couldn't be established.
    die(print_r( sqlsrv_errors(), true));

    When I execute the page I see the first two echo lines I wrote, but after this line $db=sqlsrv_connect($server,$connectinfo); nothing happens.
    I wrote the php.ini line with the other extension lines, does it makes any difference?
    thanks for your help!

    1. Hi Alvaro

      Have you installed SQL Server Native Client 2012 ?

      Try to find your PHP log file and see what error is reported...

  4. Okay.....I did it!!! Thanks Rob this blog is really helpful!!! The problem was that for some reason the php.ini file wasn't being updated so I opened the php.ini file form the wamp server logo and I saw that the lines you told me to add were missing.I wrote then and the connection is finally working!!

  5. Hello Rob,
    the last days I tried to set up a connection a MSSQL Server without any success. Today I found your blog and I read every step you did and realized i did the same. But maybe I made a careless mistake. Here some info about my config:

    - I am working on a Windows 7 64 bit machine
    - PHP version is : 5.4.8 nts (dir is : D:\Development\PHP\PHPcore\)
    - downloaded the SQLSRV30.EXE put the files in my ext folder of PHP (D:\development\PHP\PHPcore\ext)
    - added the following lines to my php.ini:
    (this should work cause i can access the following function without getting and unknown function error : sqlsrv_connect)
    - downloaded the SQL Server Native Client in my case the 64 bit version and installed it (could not change the install path or anything)
    And here is the problem : When i run the sqlsrv_connect function and check if it is set up propperly with print_r( sqlsrv_errors(), true) I get following error:

    ( [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: [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: ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Der Datenquellenname wurde nicht gefunden, und es wurde kein Standardtreiber angegeben [message] => [Microsoft][ODBC Driver Manager] Der Datenquellenname wurde nicht gefunden, und es wurde kein Standardtreiber angegeben ) )

    You can ignore the german part.

    Can you see a mistake here ? Did i forget anything ? I hope you can help me.

    Thanky you in adavance


    1. Hi Aleks

      The error is saying that the ODBC driver could not be found... did you install the 2012 Native Client from here: ?

    2. Yes i did :/. But did not restart PC if this is necessary.

    3. Hi Aleks,

      Could you open your list of ODBC drivers and see if "SQL Server Native Client 11.0" is on the list?

      A quick way to launch the ODBC Control Panel applet is Start / Run / then type "odbcad32" in the Run dialogue box. Select the "Drivers" tab when the dialogue is displayed.

    4. Hi Rob,

      i see the SQL Server Native Client 10.0 on the list but not the 11.0.

    5. Hey, it seems that this was the problem. I had an old version (they really shouldn't name the installation files allways the same). Thank you very much Rob !

  6. great stuff but:
    when I try to install the X64 SNAC for 2008 R2, I get told that "the feature you are trying to use is on a network resource that is unavailable" and then "the installation source for this product is not available". is the sqlnclix64.msi file not a standalone installer for the native client?

  7. ah. had moved original install files to savfe space.
    once I pointed to that folder, install was fine.

  8. Thanks Rob! this solved my issues on xampp

  9. I've been stuck on this all afternoon. Here's what I have:

    Windows 2008 Server 64-bit
    SQL 2012 Natice Client installed
    PHP version 5.3.8
    SQLSRV30 files extracted to correct ext folder
    Zend Extension Build shows API220090626,NTS,VC9
    The following lines are in the correct php.ini file:


    I have entered IISRESET and rebooting the OS, but Registered PHP Streams does NOT include sqlsvr.

    What am I missing???


    1. Hi Dan

      Everything looks ok. Have a look in your PHP log file to see if there are any error messages.

    2. The PHP error log has not been updated (this is a VM made from an image of a production server. Is there anything other than the IP & Name that needs to be changed?)

    3. As I stated, this is a VM made from an image of the production server. The bindings had not been reset so my phpinfo page & SQL test query PHP page were running on the production server, where SQLSRV30 had not yet been placed.


    4. Glad it's working Dan.

  10. This comment has been removed by the author.

  11. i get stuck find solution installing php driver until i found your blog. and now my problem was end. thanks a lot, your article really helpfull.

  12. Thanks for this information I appreciate you that you share the method of install Microsoft SQL server.
    Hire Dedicated PHP Developers | .NET Development Company

  13. This comment has been removed by the author.

  14. Hi Rob,
    I did the same steps you mentioned but i am not able to run sql server and continuously getting Fatal error: Call to undefined function mssql_connect() . Please can guide me about what can be the problem.

    Windows 7 64 bit.
    PHP 5.3.13
    Sql Server Native client Installed and can see 11.0 in Drivers List.

    For SQLSRV30.EXE, PHP 5.3, TS, VC9 add lines:

    Help will be highly appreciated.


    1. This sqlsrv driver from Microsoft is not a straight upgrade of the old mssql driver (which was programmed by the php group).

      Instead of mssql_connect you need to call sqlsrv_connect().

      Some work is required in older php apps, usually an abstraction layer provides the best way to upgrade. You write each of the old mssql functions in php code, which map and translate calls to the new driver.

  15. Hi Rob,

    Thanks for your reply i am trying to connect using sqlsrv_connect() but still getting the same error. but i have found some warning in Apache log.

    PHP Warning: PHP Startup: Unable to load dynamic library 'E:/wamp/bin/php/php5.3.13/ext/php_sqlsrv_53_nts.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0

    Warning: PHP Startup: Unable to load dynamic library 'E:/wamp/bin/php/php5.3.13/ext/php_sqlsrv_53_nts.dll' - %1 is not a valid Win32 application.

    in Unknown on line 0

    PHP Warning: PHP Startup: Unable to load dynamic library 'E:/wamp/bin/php/php5.3.13/ext/php_pdo_sqlsrv_53_nts.dll' - %1 is not a valid Win32 application.\r\n in Unknown on line 0

    Warning: PHP Startup: Unable to load dynamic library 'E:/wamp/bin/php/php5.3.13/ext/php_pdo_sqlsrv_53_nts.dll' - %1 is not a valid Win32 application.

    in Unknown on line 0

    and my OS is 64 bit... is that wamp which is 32 bit?

    Please help me out.


    1. Yes you need the 32 bit version of PHP. If using WAMP, install the 32 bit version. See my next comment to Maximiliano too...

    2. Hi Rob, I already did that, installed everything in 32 bit and, no success either.
      So, I installed a wamp solution, WampServer, never used this things so, I don't know if this is a good product but, with that the driver is loading normal!
      I still want make the things work manually, the WAMP solution have PHP 5.4.3 and PHP is already in 5.4.11 build, I want everything updated but, I'm tired of trying for now.

      Many thanks to your reply, in a few days I'll probably try again, I'm a kind of crazy with things that I want to do.

      Best regards

  16. Hi man, I'm trying to make things work for mu on windows + php + sql server but, I just can't go to success.
    I just did what your article says but, no success.
    My configuration is:
    Windows Server 2008 R2 64 bits (Amazon AWS)
    Apache 2.4.3 64 bits
    PHP 5.4.11 Non Thread Safe VC9 running with fast-cgi

    I already tried everything that I know but, but no success.
    My phpinfo file doesn't show me the extensions loaded and the function sqlsrv_connect return the undefined error.

    So, if you can help me I'll appreciate, thanks anyway.

    1. Is that a 32-bit build of PHP, downloaded from ?

      Assuming it is, make sure that you have installed the VC++ 32-bit redistributables, which may not already be installed on Win64. Install both of these for good measure:
      VC10 x86:
      VC9 x86:

      Have a look at your php log file to see if any messages there give you a clue. If not, you could also look in the Windows Event Viewer.

  17. Just a quick note here - to use the SQLSRV driver you need 32-bit PHP, as standard.

    It should run on Apache 64 bit + mod_fcgid.

    Install the x86 VC++ redistributables from Microsoft (see comment to Maximiliano above).

    Then set up mod_fcgid... see:

    Here is how I set it up in httpd.conf Apache 2.2 on a test server (a production server should have different timeouts):

    LoadModule fcgid_module modules/
    #Change any of these as required:
    FcgidInitialEnv PHPRC "C:\Program Files\PHP\"
    FcgidFixPathinfo 0
    FcgidIOTimeout 1800
    FcgidConnectTimeout 10
    FcgidIdleTimeout 1800
    FcgidBusyTimeout 1800
    FcgidMaxRequestsPerProcess 500
    FcgidProcessLifeTime 3600
    FcgidMaxRequestLen 20000000
    FcgidOutputBufferSize 0
    OutputBufferSize 0
    FcgidWin32PreventOrphans On


    AddHandler fcgid-script .php
    FcgidWrapper "C:/Progra~1/PHP/php-cgi.exe" .php


    # don't forget to include directive ExecCGI to your directory Options.
    # e.g. Options MultiViews Indexes FollowSymLinks ExecCGI

  18. Hello Rob, I'm trying to install Native Client 2012 from the same link you posted, but when I try to run it the following error appears: 'There is a problem with this windows installer package, missing a dll ...'

    I'm using: Windows 7 Pro x64, x86 apache 2.2, php 5.4 ts, sqlsrv.exe 3.0 (php_sqlsrv_54_ts).

    Can you help me? My email

    1. It sounds like an issue between Windows 7 and Windows Installer. There are some solutions on Google - try doing a search using the exact error message you are seeing.

  19. Hello Rob, thank you very much for the great post! After getting your code for Windows XP and PHP 5.4, I did the following:
    1) extracting the files "php_sqlsrv_54_ts.dll" and "php_pdo_sqlsrv_54_ts.dll"
    2) pasting the files into the php/ext directory
    3) defining the values
    in php.ini

    After restarting the webserver, I got the following error:

    "CDbConnection failed to open the DB connection: SQLSTATE[08001]: [Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could not open a connection to SQL Server [53]."

    I already did the TCP/IP changes on the server, but it still did not work. What could it also be?

    1. Hi Maurice, this is a SQL Server security problem you have to go to the SQL Server Configuration tool, look for Named Pipes protocol and give access to the IP addresses you are using to connect into SQL Server.

    2. Hey Maximiliano, thanks for the fast reply! Now I have activated the protocol over the configuration manager and over "Cliconfg" but the problem still persists. Is there any documentation that describes the process in detail?

    3. Hi again Maurice, try this article, just check if the things are like this.
      Remember that the IP address you are using in the connection parameter must be enabled in SQL Server

    4. That was exactly the guide that I was trying out before :). Also I tried to temporarily deactivate the firewall, but had no luck :(.

    5. Please, show me your connection config. Just the server part.

  20. Okay, here it is:
    - checked the checkbox "Allow remote connections to this server"
    - in "Cliconfg" the configuration on the server is:
    - "Enabled protocols by order" -> TCP/IP | Named Pipes
    - checked checkbox "Force protocol encryption"
    I restarted the server after applying these changes. If you need some more info, please tell me.

    1. I want the PHP config, the connection parameters in PHP script, you of course omit the user and password lines.

  21. No, the configuration worked before. But there seems to be another problem that I have to solve at first. The system seems not to be reachable over the network. I need to check this. Maybe this is already the answer. But thank you very much, you helped me a lot!!!

    1. Ok man, my guess is about the IP address that you are trying to bind.
      I'll give you my SQL Server config that is working fine on a AWS Machine:

      Client Protocols:
      Default Port: 1433 (MUST BE SET);
      Enabled: Yes
      Keep Alive: 3000
      Keep alive internal: 1000

      Named Pipes:
      Default Pipe: sql\query
      Enabled: Yes

  22. Wow amazing information about PHP development. PHP is best programming for custom website design in easy way so speedy also. PHP Application Development Company provide total solution for PHP.

  23. Wooo hoo! bro... this worked like a charm. I followed your step by step instructions and it worked at first shot.

    MSSQL is talking to me through a blazing fast channel. This is why I love open source.
    What MS stopped supporting, you blazed through it.

    I can't thank you enough!!

    Paras Parmar

  24. This is great tips for microsoft sql server intallation.

    PHP Development Company

  25. Hi, Thanks for great information
    I have PHP 5.3.10 installed on 2008 64bit.
    I downloaded the SQLSRV30.EXE as well as SQL native client 11. I even updated VC++ VC10 and VC++ VC10
    I added these to php.ini
    But after restarting IIS I dont see these driver in my phpinfo.
    also I am running Plesk 11 and there are serveral php.ini (but based on plesk the main one is on
    C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP53
    but I dont see the MS SQL driver at all
    can You tell me what is am doing wrong?
    Thanks again

  26. Thanks a lot, this is so usefull.

  27. You might want to edit this part...

    For SQLSRV30.EXE, PHP 5.3, TS, VC9 add lines:

    For SQLSRV30.EXE, PHP 5.3, TS, VC9 add lines:

  28. Really useful, thanks Rob. There's alot of info out there for installing SQLSRV on PHP, but it's not collated anywhere as well as you have here. Cheers.

  29. Thanks for your work!
    For Sqlserver with PHP 5.4 on IIS6 the Yours is the only way!


  30. robe Thanks, was very helpful tutorial

  31. Hello,
    I have problem with my first test app using sqlsrv.

    I downloaded php_sqlsrv_53_ts_vc6.dll and copied to php/ext, update php.ini.
    So I can see sqlsrv in phpinfo, but when I try sqlsrv_connect it returns " This extension requires either the Microsoft SQL Server 2008 Native Client (SP1 or later) or the Microsoft SQL Server 2008 R2 Native Client ODBC Driver to communicate with SQL Server. Neither of those ODBC Drivers are currently installed. Access the following URL to download the Microsoft SQL Server 2008 R2 Native Client ODBC driver for x86:"

    When I run odbcad32 I can see SQL Server Native Client 11.0

    Is there anything else, to make it work?
    I didnt create any database yet, and actually I dont know how (is there something like phpmyadmin for mysql?)

    I am quite desperate, and running out of ideas, how to solve it :-(

    Thanks for every help.


    1. Try installing SQL Server 2008r2 Native Client:

      On the Microsoft site, click 'Install Instructions' to drop down a list that contains SQL Server Native Client.

      You can install it side-by-side with Native Client 11 (confusingly, that is the 2012 client)... afterwards you should see a new driver appear named 'SQL Server Native Client 10.0'.

  32. Thanks for all the comments.

    I am currently working on builds for PHP 5.5.

  33. Thanks Rob for this resource.

    I have a WinXp SP2/ Apache 2.2 / PHP 5.4 working well but I would like to have the MSSQL extensions (both normal and PDO).
    I've downloaded your PHP_SQLSRV30 (the files inside are named exactly to the official drivers, not as said in point 3.3 ???) and extracted the content of the 'bin' folder to my extensions folder.
    I've installed the SQL Server Native Client 2008 x86 perfectly, I run the command: >"C:\PHP\php.exe" -i | more < and the PHP Extension Build is TS,VC9, I copied the appropiate Dynamic Extensions:
    If I restart the Apache, i get an error. If I try the to get information from the php startup with >"C:\PHP\php.exe" -i | more <
    I have an alert saying: error starting because MSVCP100.dll has not been found. After accepting the message, I get a PHP Startup: Unable to load dynamic library "c:/php\ext\php_sqlsrv_54_ts.dll" Module not found. But there is a file named like this in this folder????. And the same with the pdo dll.
    I'm lost, any suggestions?

  34. Done, and working.
    It was the MSVCP.dll, I've installed the Microsoft® C Runtime Library, Microsoft® Visual Studio® 2010 and restart the computer, OK.

    Hope that helps.

    1. Thanks Carlos, I've altered the orange text slightly.

      You must be using my unofficial build, there's a very small note underneath about VC10.

      For everyone else, this is the link to the VC++ 10 redistributables:

  35. Hi Rob,
    i am using windows xp with PHP 5.4 and i have followed your instructions and updated php.ini file as [PHP_SQLSRV]

    when i connected to sql server 2008 database, i am getting the below error.
    [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'user'

    but when i use the same user in sql server management studio i am able to login to the database.
    please help me out.

  36. Hi Rob,
    Please find my details:
    PHP Version => 5.4.15
    System => Windows NT SABI-MGSWD01 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586
    Compiler => MSVC9 (Visual C++ 2008)
    Architecture => x86
    PHP Extension Build => API20100525,NTS,VC9
    Thread Safety => disabled
    IIS 7.5 is the Web Server (IIS) role in Windows Server® 2008 R2

    1. I have installed the driver(SQLSRV30.EXE) for PHP5.4.
    2. Added following code in php.ini
    3. Restarted the IIS
    4. Restarted PC

    But I could not see the section 'PHP_SQLSRV' in my php.ini file
    What should I do?

  37. This comment has been removed by the author.

  38. Hi Rob
    thanks for the information, u are awesome...dont why microsoft have to make everything so complicated...

  39. ERROR ::
    Windows Server 2003 SP2/IIS6 and PHP 5.3.x?

    Microsoft SQL Server 2008 Native Client is already installed

    [0] => Array
    [0] => 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:
    [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:

    [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


  40. Thanks for tutorial Rob, Very well written !!

  41. Rob,
    the app is throwing the following exception:

    SQLSTATE[28000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'logon'.

  42. oh.. my... GOD!!!!
    Here's an alternative method for people who don't need MS for work:
    1. Install debian/ubuntu/mint
    2. sudo apt-get install lamp-server^

  43. Great To Read Your Post!!! There are actually quite a few different types of Cheap Hosting services available today that will allow you to have your own domain name and host a website on the Internet. The type of web hosting that you need, including the amount of space and the specific functionality, will determine the amount of money that you’ll need to spend in order to be able to host your website.

  44. Hi.. Rob,
    I am using Wampserver2.4-x64(php 5.4.12 & apache 2.4.4) on windows sever 2012 (64bit) with sql server 2012 using SQLSRV30.exe for dll but unable to load the extensions even all are visible at wamp tray.
    please help is these configuration are compatible.

    1. The driver on this page only works with 32-bit php. It is possible to install 32-bit php on a 64-bit web server by using the fastCGI interface. PHP 5.5 comes with a 64-bit build, but there is no official MS release for the driver yet. A 64-bit php 5.5 sqlsrv driver can be found with a Google search, it was built by someone else.

  45. Hello Rob. I'm stuck on #5 -- the run command windows rushes through so fast I simply can not read anything at all. How do I get it to stop so I can scroll through it?

    1. Hi Sue, did you add ' | more ' to the end of your command? It should run the listing and prompt you to press a key when the page is full. You could always run this command instead:
      "C:\PHP\php.exe" -i > c:\phpinfo.txt
      Then open file c:\phpinfo.txt to see the whole php information.

    2. Thank you. I really appreciate the hand-holding. I am a complete newb. My PHP version is 5.5.6 and my Extension Build is NTS VC11. What driver should I be trying to use?

    3. Hi Sue, sorry but I've only got instructions up to PHP 5.4, I'm working on something else at the moment. The driver for PHP 5.5 hasn't been released by Microsoft yet, but someone has built one:
      The installation instructions follow the same pattern as the instructions here, try to use a common sense approach installing the PHP 5.5 VC11 NTS driver. You have not said if you're trying 32 or 64 bit PHP, that's an extra factor to consider, but choose the sqlsrv driver that matches.

  46. Hi Rob
    I have Os system like this :
    Windows 8 64 bits
    I installed : Apache 2.4.7 (Win64)
    and php-5.5.7-Win32-VC11-x64
    drivers Apache PHP : php5apache2_4
    SQL server 2008 : Shard Memoy Enabled
    Named Pipes Enabled
    TCP/IP Enabled
    VIA Enabled
    I installed also The sql server 2012 native client
    and the pilote SQLSRV30
    I checked the odbc drivers there are :
    SQL Server Native Client 10 and SQL Server Native Client 11, but when I go to SQL SERVER CONFIGURATION MANAGER, I see only the SQL NATIVE CLIENT 10.0

    The issue that the page info().php is without-mssql" "--without-pdo-mssql ?

    I realy need the help

    1. Hello Wafa, you need to find a driver using Google as follows:
      Sqlsrv driver, php 5.5, thread safe, 64-bit.
      This link might have it, it's nothing to do with me:

  47. Hi Rob, thank you for the post. It helped me a lot. Please keep on writing.

  48. Does SQLSRV also supports windows 8 ?

    1. Yes, but the important compatibility is not the version of Windows, but these:
      * Your PHP version
      * Your SQL Server Native Client version.

  49. Thank you very much mate, you just saved my day!

    FYI I had the same problem as Maurice, I solved by using in the DSN of the PHP PDO connection
    the windows ODBC Data Source.

    My PC config:
    windows server 2003
    MS SQL Server 2005
    PHP 5.3.28

    Basically I created a new Data source (you can create a new one trough the control panel/administrative tools/data sources) that point to the database and than I connected the PHP to the DB via PDO


    If you have to create a new data source please do not use spaces in the name, otherwise the hell will unleashed and you'll have to sell your soul :D

    Thank you again!

  50. Muchas gracias, fue una súper guía la mejor que pude encontrar.
    En mi caso el no funcionamiento del driver se debía a que Wampserver tiene que ser de 32bits.
    Especificaciones por si alguien tiene las mismas características:
    * Windows7 64Bits.
    * Wampserver 2.2 32Bits.
    * Driver SQLSRV30 64Bits.
    * php_pdo_sqlsrv_53_ts
    * php_sqlsrv_53_ts

  51. Hello Rob, i so much love the way you respond to everybody. Please im having a problem and im at a client office and frustrated now .I have window sever 2008 64Bit, PHP 5.3 32bit installed using XAMPP. Apache 2.2.21 and MSVC9 (Visual C++ 2008) . In my php.ini file, pdo_sqlsrv is installed, pdo_odc is showing, all my dll are showing in the "ext" directory i also included pdo_sqlsrv_53_ts.dll and sqlsrv_53_ts.dll. ODBC Driver panel is also showing SQL Native Client 11 and 10. But my YII application is still showing error

    CDbConnection failed to open the DB connection: SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86:

    Please help meeeeee

  52. Hi, I have WinXp SP3, Php 5.4.16, API220100525,NTS,VC9, MSSQL 2005. I found out your blog because I am having trouble to use CakePhp. The error is "CakePHP is NOT able to connect to the database."
    "Database connection "Sqlserver" is missing, or could not be created."
    Shouldn't be an option like this "For SQLSRV20.EXE, PHP 5.4, NTS, VC9" in step 6?
    I already have SQL Server Native Client.
    I am running Apache 2.2 Zend.

    Just to be sure I copy all dll files into phpext and try each option with NTS and VC9.
    All of them gives me an error after restart Apache except this:

    Could you please help me

    1. Got it! Used:
      Thanks a lot!

  53. This is great! thank you ever so much for this article. i have trying for hours on this until i figured out the problem thanks to this blog. the problem was SNAC was not installed!!!!!!

  54. This comment has been removed by the author.

  55. Amazing, finally i reach the db engine, i got a error msj:

    Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error de inicio de sesión del usuario 'NT AUTHORITY\SYSTEM'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error de inicio de sesión del usuario 'NT AUTHORITY\SYSTEM'. ) [1] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]No se puede abrir la base de datos "dbConsola" solicitada por el inicio de sesión. Error de inicio de sesión. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]No se puede abrir la base de datos "dbConsola" solicitada por el inicio de sesión. Error de inicio de sesión. ) [2] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error de inicio de sesión del usuario 'NT AUTHORITY\SYSTEM'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Error de inicio de sesión del usuario 'NT AUTHORITY\SYSTEM'. ) [3] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]No se puede abrir la base de datos "dbConsola" solicitada por el inicio de sesión. Error de inicio de sesión. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]No se puede abrir la base de datos "dbConsola" solicitada por el inicio de sesión. Error de inicio de sesión. ) )

    in few word i cant log in to the db engine, im working with a local instace that i call "." usng windows autentication, so i dont send user and pwd on my array...

    what i can do to solve this?

    tks for ur help

    1. Hello David

      This proves the driver is installed and working. Your problem is authentication. Which user is attempting to gain access to your database? Grant access to the user and it will work.

      From this message it looks like your web is running as 'LocalSystem', therefore so is PHP. Therefore, just add this Windows user ID to your logins and databases in SQL Server: NT Authority\SYSTEM, or LocalSystem.

  56. hi Rob , i get error call to undefined function sqlsrv_connect (), with w7 sp1 ultimate mssql2012 and xampp php 5.5.9
    I did all the steps, but in the end when I run my application, I have an error, call to undefined function sqlsrv_connect (), but also did the same in w8 mssql2012 64bit with xampp 5.5.9 and if it worked

    1. When it says 'undefined function', it means the driver isn't loaded. See if you can spot an error in the log about the driver failing to load.

  57. already checked everything, the administrator of sources contains ODBC SQL Server Native Client 11.0 driver, my php is 5.4, I'm using xampp and I put everything continues the same error occurring

    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: [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: ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Nome da fonte de dados n�o encontrado e nenhum driver padr�o especificado [message] => [Microsoft][ODBC Driver Manager] Nome da fonte de dados n�o encontrado e nenhum driver padr�o especificado ) )

    1. Just for good measure, please could you look at step 3.1.1 or 3.1.2 and install the native client again, it will not harm your computer. Then restart apache before you retry.

      If it still does not work, please post your Windows version, and the php code you are trying to run.

    2. This comment has been removed by the author.

    3. already reinstalled the whole package of 11 Native Client, restarted apache and still the same error, my SQL Server is 2008, my Windows 7 Ultimate is the SP1, 32-bit, since I do not know what to do
      my code

      $ db, "UID" => $ user, 'PWD' => $ password);
      $ conn = sqlsrv_connect ($ serverName, $ conninfo);

      if ($ conn === false) {
      echo "connection failed
      die (print_r (sqlsrv_errors (), true));

    4. Hi, thanks for the information. There is another comment on this page from someone who had a similar problem, please could you check to see what drivers are on your system:

  58. Hi Rob,

    I was trying to connect php to sql server. I already did it in my local but I was experiencing error while doing it in the server. I already put the library in the ext folder and edited the php.ini however I'm getting this error message "Call to undefined function sqlsrv_connect()". Btw I'm using WAMP server

    1. Hi, the driver isn't loaded... check you've installed the SQL Server native client, which is Microsoft's odbc driver (there are direct links to it in step 3 above). If you have - let me know what version of Windows and PHP you have, and whether your WAMP version is 64 bits, and I'll try to help.

      You might need a newer build of the driver, which is in a page on this blog called "Unofficial Microsoft SQL..."

  59. This works on Windows Server 2012 R2 with SQL Server 2005?
    Because I follow the instructions, and works in Windows 8, but in the Server the driver isn't show in the phpinfo() from XAMPP.
    Thanks in advice for the attention ;)

    1. It's Windows Server 2008 x64, PHP 5.5 x86, SQL Server 2005.
      Also, I need to install the Apache service?

    2. Hi Eduardo, for PHP 5.5 you need the unofficial driver, please download it from here:

      The instructions in orange on this page will work for the unofficial driver (start from 1.3 orange text)

      By the way, you don't need Apache, use IIS with Windows, it's an excellent web server.

    3. I follow the orange instructions. In my laptop works great, the unofficial driver for PHP 5.5 in Windows 8 with Apache connect to SQL Server 2008
      But in the Windows Server 2008 x64 with PHP 5.5 x86 in Apache the sqlsrv isn't show in the phpinfo(). I'm not sure if is due the WS 2008 or an error installing Apache, or maybe I do something wrong in the instructions.
      PS The server have install the SQL Server 2008 Native R2 Client, SQL Server Native Client and the databaase is SQL Server 2005
      Many thanks for your answers :)

    4. All I can see from your config is that you have Apache with 32-bit PHP on Win 64... you need one of these types of config:

      1. Apache 32-bit VC11 build (from ApacheLounge) using PHP module, and PHP thread-safe with TS sqlsrv drivers

      2. Apache 64-bit and mod_fcgid (or other fcgi) and PHP non thread-safe, with NTS sqlsrv drivers to match

      For both of these, you need the 64-bit SQL Server Native Client - you can check if it's installed by running ODBCAD32.EXE and looking at the 'drivers' tab. Hopefully you will see "SQL Server Native Client 11.0" on the list.

    5. The server have the first configuration (PHP 5.5 32-bit, VC 11 and TS). Don't have installed the SQL Server Native Client 11, but my laptop neither have it installed and it runs.
      Also, in the XAMPP Control Panel, when start the Apache as a sevice, and having extension=php_sqlsrv_55_ts.dll
      uncommented in the php.ini, the server shows "httpd.exe Failed to start because MSVCP110.dll was not found". But the file exists in C:\xampp\php. And when commented those lines, or when start the Apache uninstalling the service, the message is not display - but still not showing the sqlsrv in the phpinfo()
      Where can be my error?

    6. I'll have a look at XAMPP. There should be no reason at all to ship MSVCP110.DLL in the PHP folder, it is wrong. It is part of the Visual C++ redistributable, and Microsoft installs it within Windows. It should never be part of an application.

      I will let you know what I find out about XAMPP later, but if they have put the VC11 redistributables in the PHP folder, they are using Windows incorrectly, it's a botch.

      Step 1:

      Did you try running ODBCAD32.EXE? If you didn't see the SQL Server Native Client in the list, please return to step 3.1.1 and install it.

      Step 2:

      Install the Microsoft redistributable for VC11 from here:
      and select "VSU_4\vcredist_x86.exe" when you click 'Download'.

    7. FANTASTIC!!! It was, the Microsoft redistributable for VC11 fix the problem! Now the sqlsrv appears in the phpinfo().
      Now it's time to create a connection for testing.
      Thank you so much from Mexico, Rob :)

    8. Glad it's working, thanks for persevering, your effort will help others if they have the same problem.

    9. Thank you!!! Microsoft redistributable for VC11 fixed the issue for me...

  60. Hi Rob,

    I have followed your instruction then how do I know my php can connect to mssql ?

    currently I use yii framework

    I have still got this massenge

    PDO MSSQL extension (pdo_mssql) Warning All DB-related classes Required for MSSQL database from MS Windows

    PDO MSSQL extension (pdo_sqlsrv) Warning All DB-related classes Required for MSSQL database with the driver provided by Microsoft.

    1. If you want to know if the driver's working, call function phpinfo() and look for a section called "pdo_sqlsrv"; if you see it, it worked.

      Sorry but I can't help with yii framework, or pdo_mssql, you have to ask them about it.

  61. Hi Rob,

    I'm running WAMP on my local computer for a test environment. I have the 32-bit version intalled with PHP 5.4. I'm now trying to connect to an officer service running a sql server instance (IIS7) and get the following error:

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server.

    I've already installed the native client on my local computer and verified it is runnning with odbcac32. Is there a way to get this setup to work? Does native client need to be installed on the server as well?

    Thank you!

    1. It's difficult to work out exactly what you mean, but if your officer service runs php with sqlsrv under IIS7 then that computer needs the native client.

    2. Ok I'll try to clarify:

      Our company has a server set up running IIS with a 2008 SQL instance. As far as I know, PHP is not installed on this server. I can connect to this instance and the DBs from my local computer using SQL management studio (windows authentication). I usually use the databases to pull data for reports etc. and also have a SSRS running.

      I have WAMP installed on my local with PHP 5.4 (32-bit) to test an interface in building. sqlsrv and native client 11 are installed on my local computer and enabled in WAMP. I would like the interface to connect to the SQL instance on the company server for testing but not sure if that's possible?

      As mentioned before, the error I get is related to the native client, which probably means it's not installed on the company server. Does that make more sense now?

      I guess I could set up a local instance of sql server and find out pretty quickly if that works.


    3. I assume then that you're connecting to SQL Server 2008 on your company's server. (It doesn't matter if it's running IIS.)

      And you are using your local computer with PHP to connect to SQL Server, so your configuration should be ok.

      But you get a message that says the Native Client is not installed - that message is usually right, so it's likely that you have the wrong version of the Native Client installed (e.g. maybe SQL Server Native Client 10.0).

      For good measure, please run step 3.1.1 (if your local computer is 32-bit Windows) or 3.1.2 (if it's 64 bit Windows) on this page.

  62. Thank you Rob!!!

    I went to step 3.1.2 and it resolved the issue. Obviously I must have had the wrong version of the native client. I set up a test account on the sql server and can now access the DB through PHP.

    Thanks again for your help.

    Btw, do you know what's going on with PHP 5.5/5.6 support? Seems like MS is behind the curve.

    1. You can get my builds for PHP 5.5 and 5.6 on this blog page titled "Unofficial php_sqlsrv...". They are safe I use them myself and support them. There are also builds on ApacheLounge by Jan Ehrhardt.

      Regarding Microsoft's position, I don't think they are active any more. The last comment in July was made here:

      I read it as saying they have given the project to the PHP group to run with. It would be ideal if each Windows version of PHP (maybe all platforms) was shipped with the driver among the bundled extensions.

      It's a good driver and better than anything else available on PHP for ODBC or SQL Server, but it could be even better. There is unnecessary clutter and code churn, and areas where it could be optimised significantly.

      I've been a Microsoft developer for a long time and feel I know them quite well... this PHP driver was something that surprised me (pleasantly), but in the back of my mind I was waiting for them to drop it. It's not their thing, but in order to extend the reach of SQL Server and IIS, they needed to embrace PHP and other open platforms. To be honest IIS, SQL Server and PHP is a formidable combination, so I hope it picks up again.

      In the mean time, we have the source code and can build or change it according to the Apache licence they distributed it under.

    2. Thanks for the info. It sounds like giving the project to the PHP group will turn out to be a good thing in the long run. It makes sense to include the driver with each new release. In the meantime I'll check out your builds.


  63. For days I have searched the Internets for a solution to make my Apache with PHP 5.5 able to talk to MSSQL Server.

    I found many solutions, and none of them worked. Then I found this page, followed the (very clear) instructions to the letter and voila: It works!

    Thank you very, very much!

  64. Thank you very, very much!

  65. This is really great efforts of this blog owner to take a time for explaining the things about install the microsofts sql in PHP server.I really appreciate.
    Website Design Companies Bangalore | Website Design Company Bangalore