Wednesday, 13 June 2012

Unofficial Microsoft SQL Server Driver for PHP (sqlsrv)

Here are unofficial modified builds of Microsoft's sqlsrv and pdo_sqlsrv drivers for PHP, version 3.0, for:

  • PHP 5.6 for Windows Vista/2008 and above (32 and 64 bit) 
  • PHP 5.5 for Windows Vista/2008 and above (32 and 64 bit) 
  • PHP 5.3 and 5.4 for Windows XP/2003 and above (32 bit)
    Microsoft's version 3.0 driver does not run on XP/2003 because it has a hard-coded dependency on the SQL Server 2012 Native Client (ODBC driver), which will not install on XP.  To fix the problem I just had to allow the PHP driver to use an older version of the ODBC driver supported by XP.



Downloads


The latest drivers are exactly the same as Microsoft's, except:
  1. All known memory leak and memory exception bugs have been fixed *
  2. Column names can contain unicode characters
  3. The newest of any of these ODBC drivers is selected, depending on what's installed:
    1. SQL Server Native Client 12.0 (hasn't been invented as of June 2014!)
    2. SQL Server Native Client 11.0 (SQL Server 2012 ODBC driver)
    3. SQL Server Native Client 10.0 (SQL Server 2008/r2 ODBC driver)
    4. SQL Native Client (SQL Server 2005 ODBC driver)
  4. 64 bit versions included for PHP 5.5 and 5.6


Builds for PHP 5.3 and PHP 5.4 work on XP and above.

Builds for PHP 5.5+ only work on Windows Vista/2008 and above - PHP 5.5+ is built with the 2012 Visual C++ 11 compiler and it generates code that works on Windows Vista and above.  I am comfortable with that - XP has been superseded a long time ago, Windows 8.1 is absolutely great, and don't forget that upgrading Windows also upgrades to a far better web server in IIS 7.5 or 8.5.

It's never a good idea to look at the source code of things you like - since I had to look, my new list of things to do includes writing a new version of this driver.  It is a wrapper around the ODBC API, and has no business making strict dependencies on any version of the SQL Server Native Client.  It should even work with SQL Server 6, because there is an ODBC driver for that too.  Furthermore, it's a pretty ugly bit of code and every update is likely to introduce new bugs.  It's still a better choice than using the PHP ODBC driver, as it's much faster in returning data, it is multilingual (nchar and nvarchar), it supports the majority of data types, and includes parameters.

* Sqlsrv changes
The sqlsrv driver has a fix to a bug found by Charles Durrant (http://sqlsrvphp.codeplex.com/workitem/22427) which I too recently experienced when running PHP-32 on a 64 bit server.  I noted Charles's post when he first reported the bug, but tried my best to avoid working on the source code until I had to... Charles saved me a huge amount of time, so thank you to him.  My fix is different, I have repaired all of Microsoft's dodgy auto pointers and completely rewritten the horrible function that caused the crash.  If anyone uses these new builds and spots memory leaks or bugs due to these changes, please let me know and I'll fix them within a day or two.

Microsoft's official downloads are here:

SQL Server Native Clients are here:

123 comments:

  1. Hello,
    Thank you a lot for this unofficial php driver, it works very well on Windows Server 2003 for PHP 5.4 with the thread-safe libraries ! :)

    Bye

    ReplyDelete
  2. Is there source code available for this?

    ReplyDelete
  3. nice work!
    finaly my SQL 2012 PDO on Win2003 and PHP 5.4.7 is working
    THANKS

    ReplyDelete
  4. Thanks a lot! you save me from reinstalling the server :)

    ReplyDelete
  5. Hi Rob,

    i needed to port a php application reading data from a MS SQL database from
    one server running windows server 2008 r2 on windows 7
    to a server running windows server 2008 r2 on windows xp.

    After porting, i encountered the same problem that you had "you need to install native client for sql server 2012" which is not available for windows xp.

    Thus i downloaded your customized driver pack, since i already have the sql native client 2008 installed, and replaced the 'php_pdo_sqlsrv_54_ts.dll' with the same file from your package in my php\ext folder.

    I left my php.ini with the configuration
    'extension=php_pdo_sqlsrv_54_ts.dll'.

    Now apparently the driver seems to load fine, because when loading the application in my browser, the connection gets established but then i encounter the following error message:
    SQLSTATE[08001]: [Microsoft][SQL Server Native Client 10.0] Client unable to establish connection because an error was encountered during handshakes befor login.

    Might you have any idea what is causing this? I can't find the corret solutions through Google (although i will keep on looking) up to now. Maybe you have an idea.

    ReplyDelete
    Replies
    1. And as it always is, just a little bit after asking, i found the fix myself.

      Just a little bit later, the error message changed into
      "Named Pipes Provider: No process is on the other end of the pipe."

      This Microsoft Support site solved the problem:
      http://msdn.microsoft.com/en-gb/library/ms175496%28v=sql.105%29.aspx

      Simply enabled named pipes in the SQL server settings using SQL Server Configuration Manager -> SQL Server-Network configuration -> Protocols for -> Switch "named pipes" to enabled -> Restart SQL server services.

      Delete
    2. Great, thanks for the information, it's useful to know.

      Also, you can try to force the connection to use TCP/IP by specifying an IP address and port instead of SERVER\INSTANCE. Each instance can be set to use a fixed port number, e.g. if you know a certain instance is using port 8000 on a computer with IP 1.2.3.4:
      sqlsrv_connect('1.2.3.4,8000', array('database'=>'DB', ...);

      Delete
    3. Thanks for the hint!
      Btw, i forgot to thank you for your work. Great big thanks! Saved me at least 2 days of work!

      Delete
    4. Any chance at all you could recompile for 64bit DLLs?
      hoping to call powershell Exchange commandlets from PHP but only 64bit support can work.
      We're stuck on 32bit version for all our SQL apps until then.

      Delete
    5. Hi Mark, PHP 5.5 is available as 64 bit, and another developer has recompiled Microsoft's code for PHP 5.5 in 32 and 64 bit, a google search will find it.

      The reason I never compiled as 64 bit is because I use the dev library released by the PHP group, which until PHP 5.5, was only built as 32-bit. Now that PHP 5.5 has arrived, PHP group is doing 64-bit builds, but there's no need to redo something that's already out there.

      Delete
    6. I had to update the driver a little bit, and 64-bit builds for PHP 5.5 have been added.

      Delete
    7. "I had to update the driver a little bit"
      Thanks Rob. Did you change any code? If so, have those improvements been submitted to Microsoft? (Even though they seem to have abandoned the project...)

      Delete
    8. I have to publish the source, it's a rule of open source licensing - so it's included with the download :-)
      To be honest MSFT supports it more than a lot of other PECL extensions, they still sort of look after the sqlsrv forum, and the code compiles, so there's not much else they need to do at the moment, except official builds.

      Delete
  6. how about a wrapper for 64bit php for windows? it has to be possible?

    ReplyDelete
    Replies
    1. Updated with 64-bit builds for PHP 5.5

      Delete
  7. Couldn't this be compiled to 64-bit? And if it were to be, would that allow us to run it with 64-bit PHP?

    ReplyDelete
    Replies
    1. Updated with 64-bit builds for PHP 5.5

      Delete
  8. Good job! Works perfectly in Windows XP 32bit(PHP 5.4).
    I can connect in the SQL Server 2012 which is running on a Windows Server 2012 64bit.
    Thanks Rob!

    ReplyDelete
  9. very happy to get working on xp/2003 machines with php 5.4. thanks

    ReplyDelete
  10. Thank you!! Using your php pdp 5.4 ts dll I was able to connect php 5.4 on a wamp server to my ms sql database 2008
    Running windows xp pro sp3

    Awesome!

    ReplyDelete
  11. Thank you!!!!! Running 5.5.13 on 2008 server with MSSQL 2008R2 on a remote 2003 server. 5 days of struggling until I read your post and used your 5.5_ts drivers. Working brilliantly. You're the man!!!

    ReplyDelete
  12. Boy do I want this download! (php_sqlsrv_3.0.2.1 for PHP 5.5, 5.4 and 5.3) Unfortunately, all I've been getting for the last 3 hours is:

    We can't show you that page
    Our server is having a problem. We're working to fix it as soon as we can, so try again in a few minutes.

    :-(

    ReplyDelete
    Replies
    1. Hi Steve, are you using the driver and it's crashing the server? Can you tell me what SQL you were running when it stopped? Also did you make sure you installed the right version of the DLL to match your php instance?

      Delete
    2. (Or is it you can't get the file from OneDrive?)

      Delete
    3. Definitely the latter. I can't get the file from OneDrive.

      Delete
  13. Hi Rob -- using Chrome from a different computer, and not signing in with my Microsoft account first, I was able to get your file! Thank you!

    ReplyDelete
  14. Hi,
    I`m trying to use MS SQL driver for PHP compiled by you, with PHP 5.5.13 and Apache 2.4.9, and I get a strange behavior: my code, where I use functions from php_sqlsrv.dll, is working only if I remove all the comments from the source code. If I have comments at the end of lines, Apache restarts and I don`t get any error (only in apache error.log - [Mon Jun 16 19:32:11.722833 2014] [mpm_winnt:notice] [pid 3272:tid 680] AH00428: Parent: child process 4484 exited with status 255 --). I use Windows 8.1 and try to access MS SQL 2014 Express edition.

    Thank you,

    ReplyDelete
    Replies
    1. Hi Marius, your exit code indicates php crashed, I'll take a look. Can you let me know what version of php you have (32/64 bit, nts/ts etc) and also which extension file you installed?

      Delete
    2. Hi Rob,

      Thank you for your quick answer. I use 32 bit TS version, and I tried only with php_sqlsrv extension, also with other extensions. The crash is happening only when I use a function from php_sqlsrv.dll, and only when the source file has more then uncertained number of comments (I have two functions in my code, first 33 lines, second 21 lines; in second function, at middle of function, if I add more then 11 tabs after the usefull code, the strange behavior starts to happen). My project is at the begining, so if I can`t find a fix, I will need to use other type of DB.

      Delete
    3. Thanks Marius. I did a quick functional test on the 55 TS module and it works. Where did you get your Apache build? Is it a VC11 build from Apache Lounge?

      Delete
    4. Hi Rob,
      I have Apache Lounge official build (httpd-2.4.9-win32-VC11.zip) from there site, and everything is VC11 (PHP - php-5.5.13-Win32-VC11-x86.zip). I get out of all the comments on my source code file and I was able to add more code to it (I use codelobster as an editor, but the something is happening also if I use other editor), but after another 20 - 25 lines (probably this was the space occupied before by comments), the some strange thing is happening. So I believe is a limitation of some sort, and for a strange reason my script file can not be processed by the compiler if is bigger. I tried to reinstall everything, configure .conf and php.ini files, and I done only minimum modifications to them. I use PHP configured as an module of Apache.
      Any idea what can I test to find out how to resolve this annoying bug?

      Delete
    5. Thanks Marius, there's nothing wrong there then. The lines of code is just a coincidence, something is causing a fault, and it could be the sqlsrv module. I will do some tests using Apache, leave it with me for now. Can you send me your php source code? (rob.johnson.b@gmail.com)

      Delete
    6. Hi Rob,

      Thank you for your help, I sent you an email with my source code from serbanm33@gmail.com.

      Delete
    7. Hi Marius

      I modified your code to make it run on my computer, added some function calls, edited the globals, etc, and I was able to run it. The sqlsrv extension works. Some things I noticed that might cause a problem are:

      * Make sure no other version of PHP is in the PATH except your Apache version.
      * Try running your script on the command line instead of Apache and see what happens.


      Delete
    8. Hi Rob,
      I tried to run my code directly in command line, with php.exe, php-win.exe and php-cgi.exe and I get "CLI has stopped working".
      What you min by "Make sure no other version of PHP is in the PATH except your Apache version"? I have Apache24 folder on my C drive, and PHP folder also in C.
      Problem details reprorted by windows:
      "Problem signature:
      Problem Event Name: APPCRASH
      Application Name: php-win.exe
      Application Version: 5.5.13.0
      Application Timestamp: 53861433
      Fault Module Name: php5ts.dll
      Fault Module Version: 5.5.13.0
      Fault Module Timestamp: 53861805
      Exception Code: c0000005
      Exception Offset: 00023c94
      OS Version: 6.3.9600.2.0.0.256.48
      Locale ID: 1048
      Additional Information 1: 5861
      Additional Information 2: 5861822e1919d7c014bbb064c64908b2
      Additional Information 3: d1d9
      Additional Information 4: d1d94a13d3609d6b740644c12508f581"

      Delete
    9. Hi Marius, I just wondered if you had maybe more than one web server or more than one php version installed.

      It is certain that one of your php extensions is causing it to crash. When I tested php_sqlsrv_55_ts.dll on Apache 2.4.9 32-bit, it worked. There might be a bug in php_sqlsrv that is triggered by a line of php code somewhere, but there isn't much I can do unless you can provide a sample of code that reproduces the crash, including the SQL and table layout if necessary.

      In the meantime I will keep looking into it, and there are a few other things you can try:

      1. You have Windows 8.1, why not use IIS 8.5? It is excellent.
      2. Use the Apache mod_fcgid to load PHP nts version as recommended by Apache.
      3. Try one of the other builds - e.g. http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e1d37219-88a3-46b2-a421-73bfa33fe433/unofficial-php-55-drivers-x86

      Delete
    10. Hi again Marius - I have just uploaded version 3.0.2.2 which fixes a bug handling output parameters, if you want to try it...

      Delete
    11. Thanks Rob, I will give it a try today and come back with the result. Regarding your questions:
      1. I do not work with IIS, primarily because I do not trust this server, and I have no experience with it.
      2. I always use TS, and in the end if I will not be able to use PHP 5.5, I will switch back to PHP 5.4.
      3. I tried actually a few builds (everything i can find) with more or less the some thing happening, but nobody is offering support for their builds, and unfortunately I can build it myself.
      Yesterday I started do some backtrace using this tutorial: "https://bugs.php.net/bugs-generating-backtrace-win32.php", I will come back when I have more information and probably the cause of my problem.

      Delete
    12. I think there might be a general problem with thread safe builds, I couldn't get the TS version of php_spidermonkey to work either; I should be able to track that one down because it crashes PHP on startup in Apache (but not on the command line). It might lead to a common solution.

      Delete
    13. After many tests of all kind, the conclusion is that combining Windows 8.1 x64 with PHP 5.5.13, Apache 2.4.9, with installation in C drive, sqlsrv and blenc (sometimes is no difference with and without blenc) extensions, is a deadly combination that make php5ts.dll to crash, but only if the code contains more than a certain number of characters regardless if we are talking about useful code or comments.
      I do not now wath exactly is the problem, but if I remove any of the items mentioned before, everything start working gest fine.
      The debugger show that sometimes blenc is crashing, or php5ts.dll is crashing, other times gest crash without showing wath was the problem. I will try also the NTS version this weekend, but in the end I think I will use PHP 5.4 for now. The new version of sqlsrv make no difference in my case.
      Thank you once again for your help and useful advices on this metter.

      Delete
    14. Thanks for all your testing Marius. I set up 32-bit Apache+PHP TS 5.5.13 on Windows 8.1 x64 and tested all the sqlsrv builds as of today (19 June) and managed to run everything without any errors. I ran httpd.exe from a console window, not as a service.

      The number of characters in your code is a coincidence; a memory exception is occurring (0xc0000005), and a crash will follow some time after the damage is done - the app (Apache) may still appear to work but exhibit strange behaviour before it finally stops.

      I hope you manage to get something working soon. I know how frustrating it is to run through different combinations of configurations to track down problems.

      Delete
    15. Hi Rob,
      I tried yesterday Apache 2.4.9 VC11 with PHP 5.5.13 VC11 NTS, on the same platform (Windows 8.1 x64), and is working just fine with your build of sqlsrv and BLENC extension active.
      Finally I can continue with my project, thanks again for all your help.

      Delete
    16. Thanks for the update Marius, that's good to know.

      Delete
  15. This comment has been removed by the author.

    ReplyDelete
  16. I think there is a memory leak with out values using the 64bit version of the driver. I'm using PHP 5.5 and when I pass out values to a stored procedure (SQLSRV_PARAM_OUT), the out value returns gibberish.

    It only happens if sqlsrv_execute returns fales (with an SQL error). I have a stored procedure that produces errors but still writes on the out value.

    ReplyDelete
    Replies
    1. Hi, can you read the 1st paragraph of this link:
      http://msdn.microsoft.com/en-us/library/ms403283.aspx
      Make sure you keep calling sqlsrv_next_result() until it returns null.

      Delete
    2. Forget that. Once sqlsrv_query, sqlsrv_execute or sqlsrv_next_result return false, the statement gets cancelled. It's not a memory leak, that's the way it was programmed by Microsoft. I'll see if I can find out where the gibberish is coming from.

      Delete
    3. By the way, i'm using sqlsrv_execute. The sqlsrv_errors I get is due to a notice from the server about email getting queued (not sure why that shows up as an sql error). Oh, and I'm using codeigniter, the gibberish I get (always almost the same) are random letters for the first 2 characters continued by the path where codeigniter logs it's messages (the path is incomplete though, truncated by the first 5 characters).

      Delete
  17. In your intro you said, "To fix the problem I just had to allow the PHP driver to use an older version of the ODBC driver". What ODBC driver is this?

    Lastly, this blog was written in 2012, so are your recent builds of this sqlsrv driver still using that "older version of the ODBC driver"?

    ReplyDelete
    Replies
    1. The latest ODBC driver for SQL Server on XP is native client 2008r2, but the PHP driver 3.0 from Microsoft needs 2012. To use driver 3.0 on XP, the driver uses 2008r2 instead.

      Actually it has a list of drivers to try, starting with the newest (2012). If it doesn't find it, it tries the previous one (2008r2), and so on. So the answer to part 2 of your question is that it uses the newest one it can find. Microsoft hasn't released a new driver since 2012, so it is still current.

      Delete
  18. Thanks a lot for your job. I installed unofficial pdo_sqlsrv drivers on Windows 2003R2 with php 5.4.30 and now all works!

    ReplyDelete
  19. works like charm on latest version of php 5.5.15 and apache 2.4.10 with x64 bit thank you uploader thanks alot...... your name will be written.......................

    ReplyDelete
  20. Rob,

    Charlie Durrant here, sounds like a positive fork of the code! We have a very vested interest in this driver and perhaps you and I could (if the licence permits) fork it and push it back to php.net and get it distributed with the windows php builds. We would have to be the maintainers but I don't think it would be much work and as I said we are very reliant on this extension in a pretty active commercial package.

    Charlie
    charlie durrant at gmail

    p.s. we have a release in the next few months and I will use your dll during our QA and load testing cycles.

    ReplyDelete
    Replies
    1. Hi Charlie, sorry for the late reply. That's great that you are using it and I look forward to hearing how it goes. The source is included with my download, and I'm quite happy to make it official in PECL as a fork and maintain it with you, just let me know what I need to do.

      Delete
  21. Rob, thanks a million for your effort. You save a lot of people's life :D

    ReplyDelete
  22. Thank you so much for your help :D

    ReplyDelete
  23. Hi,

    In order to work with Zend Server 7 CE, needed PHP 5.5 non-thread safe drivers build for VC9. This was not included Rob's excellent package. So, using the sources from Rob, together with the PHP 5.5.20 sources, I have built the necessary drivers.

    If anyone want these, please reply to my comment. Are you willing to include these in your package?

    ReplyDelete
    Replies
    1. Hi Theo, I think you should hassle Zend to use a normal PHP build, I don't want to make things complicated. The reason I can't do it is because I don't build the whole of PHP, I use the dev libraries included in the standard releases.

      Delete
    2. I will hassle them. In my view, Zend not including MS SQL Server drivers is every bit as ridiculous as Microsoft not providing SQL Server drivers for the latest PHP standard release.

      Delete
    3. And if they (Zend) don't, can I recommend the wonderful Netbeans for PHP?
      * It supports Zend/Zend2 frameworks
      * It supports XDebug (to replace Zend debugger)
      * You can run any version of PHP and set up the extensions how you like
      * You can use any web server, IIS, Apache, etc.

      Delete
    4. I would like to get the 5.5 NTS VC9 ones please. Thanks

      Delete
    5. Files are located at https://www.dropbox.com/sh/0zdp3e80et00n2p/AAAdvdOg5AChoJdH2jHW2UbAa?dl=0

      These are only useful for Zend Server 7.x which builds PHP 5.5 using VC9. The standard build of PHP is VC11.

      With the above exception, use the files provided by Rob.

      Zend Server 8 (for PHP 5.6) is build using VC11, so the driver provided by Rob should work in this case.

      Delete
  24. So, is there anything in the works for 5.6?

    ReplyDelete
    Replies
    1. It's included, Theo is referring to Zend server, which doesn't use the standard PHP builds.

      Delete
    2. You mean Zend 5.6? No,sorry.

      Delete
    3. I expect I would build the drivers when Zend Zerver 8 is out of beta.

      Delete
    4. Zend Server 8 for PHP 5.6 works with the drivers supplied by Rob.

      Delete
  25. First of all, Rob, thank you very much for this library. I was wondering, perhaps it is possible to implement one more minor fix into it? When selecting "float" values from SQL leading zero is always omitted. For example: SQL 0.12 -> PHP .12; SQL -0.30 -> PHP -.30 ...

    ReplyDelete
    Replies
    1. Hi Ivan - I don't want to diverge from the functionality of Microsoft's driver - these are essentially just builds of Microsoft's software.

      Your question was asked a while back on Microsoft's forum, there are 2 answers by me that might help you find a workaround:

      https://social.msdn.microsoft.com/Forums/sqlserver/en-US/6cc6d0b4-4aec-4f29-9fa5-ad88417a6a30/driver-omitting-leading-zero-in-decimal?forum=sqldriverforphp

      Delete
  26. You are a freaking saint Rob. Your 5.6 driver saved the day for me. Thanks!

    ReplyDelete
  27. Hi Rob, that's really great job! Can I use it for production - Win 2008 R2 + Apache 2.4.12 win64 + PHP 5.6.5 VC11-x64 ? Thanks!

    ReplyDelete
  28. Hello...! Rob
    im using windows 8.1pro (64 bit), im unable to connect php and sql server2012 using apache XAMPP 1.8.1 PHP 5.4.7
    So, please kindly help me out.

    ReplyDelete
  29. whenever im connecting of localhost on browser im facing a 402 error. object not found.

    ReplyDelete
    Replies
    1. Hi, is there any message in your php error log?

      Delete
  30. Great post rob, very usefull. Have you try to compile sqlsrv driver for PHP version 3.1 release on 2014 december 12th? Are you planning? Now any place with it for 64 bits?

    Regards

    ReplyDelete
    Replies
    1. Hi Reynier, I'm not planning to build from it just yet, it is not significantly different to the code I am building from.

      Delete
  31. Hi works like a charm under Server 2012 R2 / SQL 2008 R2 with old PHP 5.3 TS (VC11)

    ReplyDelete
  32. Hi I am hoping you can help me. I followed the steps described in this post to get php 5.4.16 running on a Server 2003 machine talking to a SQL Server Express 2014 database. I got it working great, but now the problem is my install of FastCGI, which I use to incorporate php with IIS and handle the SSO application which validates Active Directory, now seems hopelessly corrupted. I uninstalled and reinstalled FastCGI and reconfigured but it hasn't worked. Here is the error I am getting...any help is appreciated.

    -------------------------------------------------------------------------------------------------
    FastCGI Error -

    The FastCGI Handler was unable to process the request.
    --------------------------------------------------------------------------------

    Error Details:

    The FastCGI process exceeded configured activity timeout
    Error Number: 258 (0x80070102).
    Error Description: The wait operation timed out.
    HTTP Error 500 - Server Error.
    Internet Information Services (IIS)
    -----------------------------------------------------------------------------------------------

    ReplyDelete
    Replies
    1. Hi Cheryl,

      FastCGI is excellent but a little bit tricky to set up on IIS 6, there are quite a few settings in different places.

      Have a look for clues in your PHP error log and remove the sqlsrv extension until you are sure your FastCGI setup is working. I recommend looking at these great blogs on IIS :

      http://www.iis.net/learn/application-frameworks/install-and-configure-php-on-iis/configuring-the-fastcgi-extension-for-iis-60

      and:

      http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis-60

      You will need the NTS version of PHP and extensions with FastCGI.

      Delete
    2. Rob, thank you so much for your suggestions, I will work on this right away this morning. I'll post my findings when I figure it out. Thanks again -

      Delete
  33. Hi again. All I've been able to figure out is that removing the extensions from the php.ini file results in fastCGI working correctly, and adding the sqlsrv extensions back in break fastCGI again. No errors related to this are being written to the php error file. I'll revisit tomorrow. Thanks -

    ReplyDelete
    Replies
    1. You've made some progress then. Your FastCGI error was a timeout, is it possible the extension is working...? Check phpinfo() and see if sqlsrv is listed anywhere. If it is, maybe your database code is taking too long, it can happen when you try to connect to a server that is down, or can't be found. If you expect a long delay, go back to Ruslan's blog on IIS and see how to increase the FastCGI timeout.

      Delete
  34. Hi.

    Thanks for providing x64 bit versions. Is there any way to get x64 versions of the 5.4 driver? I'm stuck with using PHP 5.4 x64 and can't do anything about it at the moment.

    Regards,

    Richard.

    ReplyDelete
    Replies
    1. Hi Richard

      I am guessing you have already been to Jan Ehrhardt's excellent builds at ApacheLounge: https://www.apachelounge.com/viewtopic.php?t=5736

      I notice that he hasn't included sqlsrv, so I will see if there are any build errors on PHP 5.4 x64 that can be fixed, and maybe we could post a reply to Jan's page to see if he can include it.

      Delete
  35. Hi Rob,

    Thank you so much for providing the x64 version. It solved the problem of "PHP Warning: PHP Startup: Unable to load dynamic library 'ext\php_sqlsrv_56_nts.dll' - %1 is not a valid Win32 application." when starting up php 5.6(x64) under win2k8r2 64bit.

    Regards,

    Nicholas

    ReplyDelete
  36. Muchas Gracias me ha servido de mucho llevaba días intentándolo.

    ReplyDelete
  37. Hello, since my last windows update this dll don't work again. Any idea? (Windows 7, x64 ; WampServer 64 v2.5)

    ReplyDelete
    Replies
    1. Hi Denis, can you see any messages in your php error log? Is Apache crashing? What was the Windows update?

      Delete
    2. (sorry for my english, i am french)

      Thank you for you reply

      there is no significant message in php error log :

      php_error
      =========
      [16-Jul-2015 10:48:49 UTC] PHP Warning: PHP Startup: in Unknown on line 0
      [16-Jul-2015 10:48:49 UTC] PHP Warning: PHP Startup: in Unknown on line 0

      Apache is no crashing, but very low to start :

      apache_error
      ============
      [Thu Jul 16 12:48:43.362703 2015] [mpm_winnt:notice] [pid 5980:tid 384] AH00364: Child: All worker threads have exited.
      [Thu Jul 16 12:48:43.381705 2015] [mpm_winnt:notice] [pid 6672:tid 476] AH00430: Parent: Child process 5980 exited successfully.
      AH00112: Warning: DocumentRoot [C:/Apache24/docs/dummy-host.example.com] does not exist
      AH00112: Warning: DocumentRoot [C:/Apache24/docs/dummy-host2.example.com] does not exist
      [Thu Jul 16 12:48:49.473979 2015] [mpm_winnt:notice] [pid 7284:tid 476] AH00455: Apache/2.4.9 (Win64) PHP/5.5.12 configured -- resuming normal operations
      [Thu Jul 16 12:48:49.473979 2015] [mpm_winnt:notice] [pid 7284:tid 476] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:42:59
      [Thu Jul 16 12:48:49.473979 2015] [core:notice] [pid 7284:tid 476] AH00094: Command line: 'D:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d D:/wamp/bin/apache/apache2.4.9'
      [Thu Jul 16 12:48:49.482480 2015] [mpm_winnt:notice] [pid 7284:tid 476] AH00418: Parent: Created child process 12304
      AH00112: Warning: DocumentRoot [C:/Apache24/docs/dummy-host.example.com] does not exist
      AH00112: Warning: DocumentRoot [C:/Apache24/docs/dummy-host2.example.com] does not exist
      AH00112: Warning: DocumentRoot [C:/Apache24/docs/dummy-host.example.com] does not exist
      AH00112: Warning: DocumentRoot [C:/Apache24/docs/dummy-host2.example.com] does not exist
      [Thu Jul 16 12:48:49.759515 2015] [mpm_winnt:notice] [pid 12304:tid 384] AH00354: Child: Starting 64 worker threads.

      Windows update :

      Windows update
      ==============
      Security update for Microsoft .NET Framework 4.5.2 (KB3035490)
      Security update for Microsoft .NET Framework 4.5.2 (KB3023224)
      Security update for Microsoft Windows (KB3077657) 2015-07-15
      Security update for Microsoft Windows (KB3075516) 2015-07-15
      Security update for Microsoft Windows (KB3074886) 2015-07-15
      Security update for Microsoft Windows (KB3072633) 2015-07-15
      Security update for Microsoft Windows (KB3072630) 2015-07-15
      Security update for Microsoft Windows (KB3070738) 2015-07-15
      Security update for Microsoft Windows (KB3070102) 2015-07-15
      Security update for Microsoft Windows (KB3069762) 2015-07-15
      Security update for Microsoft Windows (KB3069392) 2015-07-15
      Security update for Microsoft Windows (KB3067903) 2015-07-15
      Security update for Microsoft Windows (KB3067505) 2015-07-15
      Update for Microsoft Windows (KB3065987) 2015-07-15
      Update for Microsoft Windows (KB3065979) 2015-07-15
      Security update for Microsoft Windows (KB3065822) 2015-07-15
      Security update for Microsoft Windows (KB3057154) 2015-07-15
      Update for Microsoft Windows (KB3040272) 2015-07-15
      Update for Microsoft Windows (KB3035583) 2015-07-15
      Update for Microsoft Windows (KB2952664) 2015-07-15

      Thank You !

      Delete
    3. Can you have a look at you ODBC drivers for SQL Server (Control Panel \ System and Security \ Administrative Tools \ Data Sources(ODBC) ) and see what driver names you see on the list (see 'Drivers' tab) ?

      I wonder if the Windows update has replaced the SQL Server native client with the new client?

      Delete
    4. Hi Rob,

      ODBC drivers (in this order in the list)
      ==========
      SQL Server ; 6.01.7601.17514 ; Microsoft Corporation ; SQLSRV32.DLL ; 11/21/2010
      SQL Server Native Client 10.0 ; 2009.100.1600.01 ; Microsoft Corporation ; SQLNCLI10.DLL ; 4/3/2010

      Delete
    5. I found a solution, I explain it in the next comment.

      Delete
    6. Until now, activated extension were present in the php.ini of "D:\wamp\bin\php\php5.5.12" and that worked very well.
      I was disconnected from SQL Server during the development although I did not modify any configuration.
      It has this moment that I realized that Windows had downloaded updates.

      The solution was to put the extensions in the php.ini of "D:\wamp\bin\apache\apache2.4.9\bin" and to remove them in "D:\wamp\bin\php\php5.5.12 " then to entirely restart WAMP.
      My previous configuration functioned well since more than one year, I thus wonder if the updates did not start the problem.

      Thank you for your help ;-)

      Delete
    7. Thanks for the explanation, and glad it's working.

      Windows can be a bit strange with DLL's. Here is a scenario that might explain what happened...

      * You have 2 processes that both need a certain DLL, process A and process B.
      * Process A has the DLL in its folder, process B does not have it.
      * Process A starts and works normally.
      * Proces B starts - it can't find the DLL, but it finds it in process A - it works.
      * Stop both processes.
      * Start process B - it won't work because it can't find the DLL this time.

      Delete
  38. Hi there,

    Any chance to get a vesion of 3.2 for x64 ?

    Thanks :)

    ReplyDelete
  39. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hi Alan, I got an email containing your comment. I'm guessing you discovered you might need to use -c CLI option to find the right php.ini, and also note that permissions will be for the current user in CLI mode.

      Delete
  40. I have tried all of the lib, but none of them compatible for PHP 5.6.12 that installed from xampp-win32-5.6.12-0-VC11-installer
    Can you help me to find it??

    ReplyDelete
    Replies
    1. HI,

      From the root folder of the zip archive, you need one of these, depending on how you've got apache or IIS set up...
      If using IIS or Apache + fastCGI or PHP on the command line, you need: php_sqlsrv_56_nts.dll
      If using the Apache module for php you need: php_sqlsrv_56_ts.dll

      Have a look in your PHP error log file for errors when loading the extension, there are other reasons it might not load. This other blog page might help:
      http://robsphp.blogspot.co.uk/2012/09/how-to-install-microsofts-sql-server.html

      Microsoft has released its own build for 5.6 which will also work with xamp win32.

      Delete
    2. Finally work good, that my idea
      First,I suspect that maybe there is different command.
      I tried and success at now.
      The problem is :
      1. The Community driver use command : "mssql_connect()"
      2. if use this driver(from Microsoft) use "sqlsrv_connect()"

      Ohhhh,,,, I find and wait for 6 month for this case.
      OK. Maybe this is for you all experience, and must be NOTED.


      Delete
  41. Are there any plans to compile this driver for PHP 7?

    ReplyDelete
  42. SQL Server drivers for PHP 7 are currently been developed by Microsoft team, follow this thread for more info https://github.com/Azure/msphpsql/issues/58.

    ReplyDelete
  43. Thanks, your copy of the unofficial drivers was the only thing I could find on the net to get my 64x PHP working

    ReplyDelete
  44. We are now in December 2015 and I still couldn't have installed this server without your help.
    Microsoft sucks.
    Thanks!

    ReplyDelete
    Replies
    1. Yes and no. Microsoft wrote the code, without it we would not have anything. At one stage I started writing a new odbc driver to replace it, but never got time to finish it, so I don't complain any more.

      Delete
  45. Thanks Rob! I did as directed , but I get the following error:

    Warning
    PHP Startup:

    why is this happening? thanks

    ReplyDelete
    Replies
    1. After researching , I came to the solution by using ODBC

      $server="localhost";
      $database="retiro";
      $user="";
      $password="";

      $conn=odbc_connect("Driver={SQL Server}; Server=$server; Database=$database;", $user, $password);
      if(!$conn) die("Connection failed: ".$conn);

      $sql="SELECT * FROM region";
      $rs=odbc_exec($conn,$sql);
      while (odbc_fetch_row($rs)){
      echo "
      ".odbc_result($rs, "nombre");
      }

      // Disconnect the database from the database handle.
      odbc_close($conn);

      Delete
  46. Hi,

    Thanks for the great 64bit driver! It's enabled us to deliver our project! Also because we were able to upgrade our PHP version to 5.5/5.6 seems like things are better. Not sure if it's just our feeling.

    I heard PHP7 is much much faster than PHP5. Would it be able to make drivers for 64 bit PHP7?

    Thanks!

    Kim

    ReplyDelete
    Replies
    1. Yes it is, every version of PHP gets faster, 5.6 is very good, 7 even better. When you combine it with powerful web servers like IIS or Apache you get a really high performing site.

      Regrettably I'm not doing PHP development at the moment, so won't be doing any more builds for the foreseeable future, sorry. Maybe someone else can pick things up - Microsoft will probably release a driver after PHP 7's official release.

      Delete
    2. What is the process of building these DLLs? If you can outline the steps and tools needed, perhaps we can continue your work.

      Thanks

      Kim

      Delete
  47. Hi Rob,

    How I can compile the source code? I need to compile those libraries using PHP5 and VC9 instead of VC11?

    cheers

    ReplyDelete
    Replies
    1. Hi Adam

      Instructions are at php.net, search for building on Windows.

      Download the source and set up the build for the entire php.

      When build works, add the sqlsrv extension from Microsoft, then if you want to use my version, overwrite the .c and .h files with the ones in the zip file on this blog.

      Naturally this process is tedious on Windows, so after a while you will learn what's needed to build the eatension on its own in visual studio. Unfortunately I haven't got time to provide those details.

      Rob

      Delete
  48. Perfect. After search by hours I found response in here. thans a lot!

    ReplyDelete

Note: only a member of this blog may post a comment.