Installing SQL Server driver for PHP - php

I have installed:
Windows Server 2008 R2 x64
IIS 7
PHP 5.5 (5.5.9) VC11 x64 Non Thread Safe (2014-Feb-06 00:36:15)
MSVC11 (Visual C++ 2012)
Sql Server 2008
Sql Native Client
Everything works perfectly except the MSSQL driver for PHP. I have Googled a lot and downloaded lots of dll files. Every time I get this error:
PHP Warning: PHP Startup: Unable to load dynamic library c:\php\ext\php_sqlsrv_54_nts.dll - %1 is not a valid Win32 application.
in Unknown on line 0
Can anyone tell me that how can I find the specified driver? Thanks in advance.

There's a clue in the file name php_sqlsrv_54_nts.dll
The "54" refers to PHP 5.4. The SQL Driver doesn't (officially) exist yet for PHP 5.5.
:(
Some people have worked on unofficial builds, but I would only use them for local testing.
Microsoft sqlsrv extension for php 5.5.x
At present official releases only work with 5.4.x

Here is a page from my blog with instructions on how to install the driver: http://robsphp.blogspot.com/2012/09/how-to-install-microsofts-sql-server.html
Look for text written in in orange which refers to my builds of the driver that support PHP 5.5 32 and 64 bit.
If you only want Microsoft's builds, avoid looking at anything written in orange.

Sharing some of my findings:
Architecture matters(x86 / x64)
PHP version matters a lot
Matching SQL Driver Should be installed.
Refer This Link to find whether your PHP version supports the driver (Refer the first table).
Refer Rob's Answer to find your Architecture and TS/NTS (Thread Safe/Non Thread Safe) of Your PHP This is His Blog
This is what worked out for me: I tried with Wampp - 64bit, Selected PHP 7.0.10 downloaded MYSQL Driver version 5.3 (Note: Refer the table i mentioned- 4th point to get the correct version)
Saved only the 64 bit TS (php_sqlsrv_7_ts_x64.dll, php_pdo_sqlsrv_7_ts_x64.dll) because my php was Thread Safe (You can find yours by refering 5th point) into the E:\wamp64\bin\php\php7.0.10\ext folder.
Added extension=php_sqlsrv_7_ts_x64.dll and extension=php_pdo_sqlsrv_7_ts_x64.dll to the php.ini, selected from wampp menu (E:\wamp64\bin\apache\apache2.4.23\bin\php.ini).
Restarted Wampp, and it works perfect.
For those who face call to undefined function sqlsrv_connect() also can follow this technique.

Related

PHP 7 on IIS: Call_user_function could not be located

I am trying to use the Microsoft SQL Server drivers with PHP 7.1 Not Thread Safe x64 on Windows 2012 R2 64-bit server.
No matter what I do I am getting an error when I run php from a admin command prompt
Warning: PHP Startup: Unable to load dynamic library
'ext\php_pdo_sqlsrv_7_nts.dll' - The specified procedure could not be
found.
Additionally it display a windows pop up that states
The procedure entry point call_user_function could not be located in
the dynamic link library C:\PHP7\ext\php_pdo_dqlsrv7_nts_x64.dll
I have verified that the php.ini is pointing to a file that exists, because if I rename the .dll file, the error messages changes to "specified module could not be found", instead of specified procedure.
I have installed Microsoft Visual C++ runtime 15 x64 as required by PHP 7.
I have installed Microsoft ODBC driver 13 as required by the Microsoft SQL Server driver.
I have rebooted the server twice.
There is nothing else I can think to even try. The Microsoft WinCache.dll is loading and working fine in PHP, as verified by phpinfo.
Confirmed what #MEmerson said above. You need to downgrade PHP to 7.0.X(?) - I used 7.0.12.
Complete Setup:
Windows 10 Pro
PHP X64 7.0.12 TS (Bitnami WAMP Stack)
Microsoft ODBC Driver 13.1 for SQL Server (https://msdn.microsoft.com/en-us/library/mt703139(v=sql.1).aspx)
Microsoft Drivers for PHP for SQL Server 4.0 (https://www.microsoft.com/en-ca/download/details.aspx?id=20098)
Same drivers with PHP X64 7.1.0 produced the error you are getting.
Microsoft Drivers 4.3 for PHP for SQL Server are now available.
These drivers contains files for PHP 7.1 - php_pdo_sqlsrv_71_nts_x64.dll etc.
I've successfully managed to connect to SQL server.
Had similar error when tried to use httpd (Apache), PHP 7.2.2, Microsoft ODBC driver 11 on MS Windows Server 2012. The text of error was:
The procedure entry point call_user_function could not be located in the dynamic link library php_pdo_sqlsrv_7_ts_x64.dll.
when I called php -m to check modules.
So I have downloaded Windows-7.2.zip from https://github.com/Microsoft/msphpsql/releases and used thread-safe dlls from it.
php -m works now as it should without giving error.
Same as NoCopy
Windows Server 2012
php-7.0.15-Win32-VC14-x64.zip from (http://windows.php.net/download)
Visual C++ Redistributable for Visual Studio 2015 (https://www.microsoft.com/en-us/download/details.aspx?id=48145)
Microsoft ODBC Driver 13.1 for SQL Server
Microsoft Drivers for PHP for SQL Server 4.0
7.1.x still a No,NO from Microsoft
It happened to me today while enabling the extensions in the IIS, where I by mistake enabled different versions for pdo & driver extensions (E.g. php_sqlsrv_7_nts_x86.dll for PHP 7.0 & php_pdo_sqlsrv_72_nts_x86.dll for PHP 7.2).
Usually the package that you download from Microsoft that contains Microsoft Drivers 5.3 for PHP for SQL Server has all the PHP extensions versions. https://www.microsoft.com/en-us/download/details.aspx?id=57163
Just make sure you enable both extensions for the same versions to avoid that error.

Is there MSSQL Server Driver for PHP on a 64-bit environment?

Is there a driver for MSSQL Server for PHP (64-bit)?
I have Apache 2.4 (64-bit) environment installed. Also PHP 5.5.12 (64-bit)
I have search for MSSQL Server driver "on the net" for php 64-bit but I found nothing. All I can find is a 32-bit. Also, all the articles that I found were old and nothing recent.
I tried to install the 32-bit driver but I get a warning when executing C:\php>php -m
This is the warning
PHP Warning: PHP Startup: Unable to load dynamic library 'ext\php_sqlsrv_54_ts.dll' - %1 is not a valid Win32 application. in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'ext\php_pdo_sqlsrv_54_ts.dll' - %1 is not a valid Win32 application. in Unknown on line 0
I downloaded the MSSQL Server Driver from Microsoft Drivers 3.0 for PHP for SQL Server
If there a MSSQL Server driver available for PHP 64-bit environment?
If not is there a workaround beside having to go back to 32-bit PHP environment?
I have run into this issue as well. What I have found is that you need to make sure that the extension=php_sqlsrv_54_ts.dll area of your php.ini file is only uncommented on the Apache location of php.ini.
For example:
if you have C:\Webserver\bin\apache\bin\php.ini, you probably have a C:\Webserver\bin\php\php.ini as well. Make sure your extension referrences are ONLY in the ...\apache\bin\php.ini.
It took me 3 hours to realize there were 2 different php.ini files and that the error was throwing because I had the extension initialized in the wrong php.ini file yet it was still looking there for some reason. I hope this helped.
Have you tried updating to php 7 ?
The x64 builds of PHP 5 for Windows are experimental, and do not provide 64-bit integer or large file support. Therefore I doubt MS will release a php5 version of the driver especially since the one for php 7 has been out for a few months now.
This MSSQL driver was release in July of 2016
Download the "SQLSRV40.EXE" from https://www.microsoft.com/en-us/download/details.aspx?id=20098
The executable is a self-extractor, unpack where you want.
You even get the PDO for the same price.
Here are the files in the package
PHP Drivers License Terms.rtf
php_pdo_sqlsrv_7_nts_x64.dll
php_pdo_sqlsrv_7_nts_x86.dll
php_pdo_sqlsrv_7_ts_x64.dll
php_pdo_sqlsrv_7_ts_x86.dll
php_sqlsrv_7_nts_x64.dll
php_sqlsrv_7_nts_x86.dll
php_sqlsrv_7_ts_x64.dll
php_sqlsrv_7_ts_x86.dll
release.txt
SQLSRV_Readme.htm
SQLSRV_ThirdPartyNotices.rtf
Tested with php 7.0, 7.1, 7.2

'Error!: could not find driver' after installing php_[pdo_]mssql.dll on WampServer

Similar questions seem to be all over the internet, but so far nothing has helped.
I'm currently running WampServer with Apache 2.4.4 and PHP 5.4.12 on Windows Server 2008 R2. According to the PHP documentation the drivers necessary to connect to an MSSQL server ship with the distribution; they do not. Neither php_mssql.dll (which the documentation claims is no longer necessary for PHP5.4, but which is still referenced in php.ini. Who knows) nor php_pdo_mssql.dll are present in the distribution.
Several sources pointed to these drivers from Microsoft, however I had no success either renaming the respective drivers to php_mssql.dll/php_pdo_mssql.dll or keeping the names the same (php_sqlsrv_54_nts.dll, php_pdo_sqlsrv_54_ts.dll, etc.) and modifying php.ini to point to the proper driver. Though I didn't get an error upon starting apache as I do when the driver is simply missing, I received Error!: could not find driver when attempting to point to a test php page at localhost.
This article seemed the most promising, but unfortunately ntwdblib.dll is not included in the zip distributions of PHP, contrary to what the article claims. This seems like it should be a laughably simple problem: missing drivers, which are supposedly readily available. And yet here I am... What am I doing wrong?
In case anyone else ends up here while trying to solve this problem, here are the steps that have worked for me the two times I've done it. These steps worked both on Windows Server 2008 R2 and Windows 8.
For my purposes, I used the latest 32-bit (x86) version of WampServer (at the time of this writing, it was 2.4, and came with Apache 2.4.4 and PHP 5.4.16). The 32-bit version is necessary, as the drivers are 32-bit; the 64-bit version will not work.
Install Microsoft Visual C++ 2010 Redistributable Package x86
Install Microsoft SQL Server 2008 Native Client x86 (Click "Download" and select ENU\x86\sqlncli.msi. Once again, the 64-bit version will not work)
Install Microsoft ODBC Driver 11 x86 (Click "Download" and select 1033\x86\msodbcsql.msi)
Install Microsoft SQLSRV driver 3.0 in php/ext/ (For my installation, this was C:/wamp/bin/php/php5.4.16/ext/)
Edit Apache's php.ini to include the line extension=php_pdo_sqlsrv_54_ts.dll (for my installation, this was located in C:/wamp/bin/apache/Apache2.4.4/bin/)
You have to place the file in the directory for PHP/ext (bin/php/ext depending on your Wamp / Xampp installation). However, you also need the SQL server native client as per: http://msdn.microsoft.com/en-us/library/cc296170.aspx

PHP 5.4.16 and FreeTDS (php_dblib.dll): Unable to load extension

Goal
Connect to a MSSQL 2008 R2 server using the FreeTDS (php_dblib.dll 0.82 + 20110906 patches) Drivers for PHP 5.4.16 (VC9).
I am unable to use any alternative to FreeTDS unless the client also decides to use an alternative. This is unlikely unless they also run into this issue when upgrading their current version of PHP (currently 5.3.x) tomorrow.
Issue
PHP is unable to load the FreeTDS extension.
The Apache error log displays this on server start:
PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.4.16/ext/php_dblib.dll' - The specified module could not be found.\r\n in Unknown on line 0
As far as I understand it, the extension is either unable to be found or is the wrong version?
The extension directory location in the php.ini has been checked and triple checked and is:
c:/wamp/bin/php/php5.4.16/ext/
That leads me to believe it is the wrong version of php_dblib.dll. I've also checked that multiple times and made sure to use the version for PHP 5.4.X Thread Safe.
Steps Taken
Clean install of WAMP 2.4 with PHP 5.4.16 and Apache 2.4.4
Thread Safe php_dblib.dll placed in PHP extension directory
extension=php_dblib.dll added to the correct php.ini
extension=php_mssql.dll and extension=php_pdo_mssql.dll disabled in php.ini
msvcr71.dll (DotNet framework 1.1) added to PHP root directory
freetds.conf added to server root directory (c:)
System Details
WAMP Server 2.4
Apache 2.4.4
PHP 5.4.16 (VC9)
Thread Safety: enabled
FreeTDS Thread Safe (php_dblib.dll) 0.82 + 20110906 patches
Microsoft SQL Server 2008 R2
msvcr71.dll (DotNet framework 1.1) only included in the PHP root directory
EDIT:
WAMP 2.4 32-bit
OS: Windows 7 Pro 64-bit
EDIT 3
Last update only applied to the 64-bit version of WAMP. I've installed the 32-bit version, again, and --without-dblib is no longer in the configure command section of the phpinfo().
Questions
With the information given, is there anything else you'd need to know about to give an accurate assessment of the situation?
I am unable to find any, but are there any known issues with FreeTDS 0.82 and PHP 5.4.16?
Temporary Defeat
I've rolled back to PHP 5.3.x for now, FreeTDS works fine on that version. I'm not sure that it will make a difference with the little bit of code I am actually delivering to the client. This was intended to be a "double" check to make sure it all works perfectly, but since I'll be on site during the install I can fix any issues if they come up.
I would like to find a solution eventually since more and more of the systems I work with every day are going to be upgraded to php 5.4 and beyond.

Connection between MSSQL and PHP 5.3.5 on IIS is not working

I recently installed IIS, PHP 5.3.5 and MySQL, and had it all working.
I then has a requirement for MS SQL as well, and what I thought would be an easy task, is now driving me crazy and I can't figure out how to make it work.
According to php_info() the MS SQL drivers aren't loading.
I downloaded php_mssql.dll and enabled it in php.ini but it didn't work. I found out that the new version of PHP uses a different dll. So I downloaded the new one, put that in the ext folder, and updated the php.ini, but still no luck.
php_info() still isn't showing the drivers are loaded.
I am about to uninstall IIS and PHP, and install Apache, which I've installed before.
This question is my last attempt, can anyone help?
This is a snippet from a customer FAQ I wrote up a wee while ago to help our dedicated hosting customers get PHP up and running with the MS SQL Drivers. It may duplicate some knowledge already imparted in the comments above, but it's completeness may also help others starting from scratch:
Note: Clearly the PHP version numbers have moved on a bit since I wrote this but the general principles still apply.
Installation Pre-requisite:
The SQL Native Client is required for the Microsoft Drivers for PHP for SQL Server:
Microsoft SQL Server 2008 R2 Native Client X64 - for 64 bit Windows
or
Microsoft SQL Server 2008 R2 Native Client X32 - for 32 bit Windows
Download and install the Native Client driver that matches your system.
PHP MS SQL Drivers:
Download the Microsoft Drivers for PHP for SQL Server:
Microsoft Drivers for PHP for SQL Server
The file is a self-extracting executable so just use 7zip or WinRAR and extract the files to a folder of your choice. We now need to decide which driver to choose that matches your PHP installation.
PHP 5.3.5 comes in four different flavours:
PHP 5.3.5 Non-threadsafe VC9
PHP 5.3.5 Non-threadsafe VC6
PHP 5.3.5 Threadsafe VC9
PHP 5.3.5 Threadsafe VC6
To tell which version you have installed open the snapshot.txt file which lives in the same folder as php.exe, php-cgi.exe etc. Don't use notepad.exe because the file uses just line feed (\n) for line ends (unix format) at the start and notepad mangles these into a single line.
In the file you will see a line (around line 6, or near the middle of line 1 of you did use notepad) starting with: Build::
Build: D:\php-sdk\snap_5_3\vc9\x86\obj\Release - non-threadsafe, VC9 build
Build: D:\php-sdk\snap_5_3\vc6\x86\obj\Release - non-threadsafe, VC6 build
Build: D:\php-sdk\snap_5_3\vc9\x86\obj\Release_TS - threadsafe, VC9 build
Build: D:\php-sdk\snap_5_3\vc6\x86\obj\Release_TS - threadsafe, VC6 build
This tells us what version of PHP you're running.
From the folder you extracted the MS SQL PHP drivers, choose the driver(s) that matches the version of PHP being used (if you're not using PDO then you don't need to copy the php_pdo_ drivers):
PHP 5.3.5 Non-threadsafe VC9: php_sqlsrv_53_nts_vc9.dll, php_pdo_sqlsrv_53_nts_vc9.dll
PHP 5.3.5 Non-threadsafe VC6: php_sqlsrv_53_nts_vc6.dll, php_pdo_sqlsrv_53_nts_vc6.dll
PHP 5.3.5 Threadsafe VC9: php_sqlsrv_53_ts_vc9.dll, php_pdo_sqlsrv_53_ts_vc9.dll
PHP 5.3.5 Threadsafe VC6: php_sqlsrv_53_ts_vc6.dll, php_pdo_sqlsrv_53_ts_vc6.dll
Assuming your PHP installation lives in C:\PHP, copy (DON'T MOVE) these files to your C:\PHP\EXT folder.
Open C:\PHP\PHP.INI and locate the Dynamic Extensions part of the file and add:
extension=php_sqlsrv_53_nts_vc9.dll
extension=php_pdo_sqlsrv_53_nts_vc9.dll <-- optional
Finally, to be sure that PHP can find these extensions, ensure the extension_dir directive in C:\PHP\PHP.INI is set to C:\PHP\EXT:
extension_dir = C:\PHP\ext
Restart IIS and call phpinfo(). If all is well you should see:
And if you also loaded the PDO driver you should see:
The above mentioned:
extension=php_sqlsrv_53_nts_vc9.dll
extension=php_pdo_sqlsrv_53_nts_vc9.dll
what I found is incorrect.
Therefore, it is likely to be:
extension=php_sqlsrv_53_ts_vc9.dll
extension=php_pdo_sqlsrv_53_ts_vc9.dll

Categories