I see that many people had issues like that, however I could not find solution that would just work.
My phpinfo() says:
PHP Version 5.4.16
Server API Apache 2.0 Handler
Thread Safety enabled
I've downloaded: http://sqlsrvphp.codeplex.com/
readme says that if I have PHP 5.4 TS I should load those files:
php_sqlsrv_54_ts.dll
php_pdo_sqlsrv_54_ts.dll
I've loaded above, but only PDO extension seems to work fine:
PDO support enabled
PDO drivers mysql, sqlite, sqlsrv
pdo_sqlsrv support enabled
However I can not see sqlsrv extensions anywhere.
I've checked PHP error.log and it's also empty.
Do you have idea why those MS libs does not work and how can I debug it?
I've small project on Windows and configuring ones stack seems to be pretty hard comparing to Linux.
Related
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
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.
I upgraded to PHP 5.3, and noticed that php_mssql.dll is missing. After googling a bit, it seems that 5.3 has dropped support for mssql. So I downloaded the drivers from microsoft, but I can't seem to get it to work.
I am on windows. What do I need to do, after I unzip the files in the ext directory of my PHP 5.3?
Quoting http://php.net/manual/en/intro.mssql.php:
The MSSQL extension is not available anymore on Windows with PHP 5.3 or later.
SQLSRV, an alternative driver for MS SQL is available from Microsoft: ยป http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx.
Once you downloaded that, follow the instructions at this page:
Loading the Microsoft Drivers for PHP for SQL Server
In a nutshell:
Put the driver file in your PHP extension directory.
Modify the php.ini file to include the driver. For example:
extension=php_sqlsrv_53_nts_vc9.dll
Restart the Web server.
See Also (copied from that page)
System Requirements (Microsoft Drivers for PHP for SQL Server)
Getting Started
Programming Guide
SQLSRV Driver API Reference (Microsoft Drivers for PHP for SQL Server)
The PHP Manual for the SQLSRV extension is located at http://php.net/manual/en/sqlsrv.installation.php and offers the following for Installation:
The SQLSRV extension is enabled by adding appropriate DLL file to your PHP extension directory and the corresponding entry to the php.ini file. The SQLSRV download comes with several driver files. Which driver file you use will depend on 3 factors: the PHP version you are using, whether you are using thread-safe or non-thread-safe PHP, and whether your PHP installation was compiled with the VC6 or VC9 compiler. For example, if you are running PHP 5.3, you are using non-thread-safe PHP, and your PHP installation was compiled with the VC9 compiler, you should use the php_sqlsrv_53_nts_vc9.dll file. (You should use a non-thread-safe version compiled with the VC9 compiler if you are using IIS as your web server). If you are running PHP 5.2, you are using thread-safe PHP, and your PHP installation was compiled with the VC6 compiler, you should use the php_sqlsrv_52_ts_vc6.dll file.
The drivers can also be used with PDO.
Download Microsoft Drivers for PHP for SQL Server. Extract the files and use one of:
File Thread Safe VC Bulid
php_sqlsrv_53_nts_vc6.dll No VC6
php_sqlsrv_53_nts_vc9.dll No VC9
php_sqlsrv_53_ts_vc6.dll Yes VC6
php_sqlsrv_53_ts_vc9.dll Yes VC9
You can see the Thread Safety status in phpinfo().
Add the correct file to your ext directory and the following line to your php.ini:
extension=php_sqlsrv_53_*_vc*.dll
Use the filename of the file you used.
As Gordon already posted this is the new Extension from Microsoft and uses the sqlsrv_* API instead of mssql_*
Update:
On Linux you do not have the requisite drivers and neither the SQLSERV Extension.
Look at Connect to MS SQL Server from PHP on Linux? for a discussion on this.
In short you need to install FreeTDS and YES you need to use mssql_* functions on linux. see update 2
To simplify things in the long run I would recommend creating a wrapper class with requisite functions which use the appropriate API (sqlsrv_* or mssql_*) based on which extension is loaded.
Update 2:
You do not need to use mssql_* functions on linux. You can connect to an ms sql server using PDO + ODBC + FreeTDS. On windows, the best performing method to connect is via PDO + ODBC + SQL Native Client since the PDO + SQLSRV driver can be incredibly slow.
Make sure to download the SQL driver here https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
Then move in the two files with the same version as your php version. (check php -v)
In my case I was using version 7.4.30 and moved the php_pdo_sqlsrv_74_nts_x64.dll and
php_sqlsrv_74_nts_x64.dll into my php folder ext
C:\Program Files\php7.4.30\ext
Then open your php.ini file and add the extensions, remember to include ".dll
" on the extensions.
extension=php_pdo_sqlsrv_74_nts_x64.dll
extension=php_sqlsrv_74_nts_x64.dll
If you still have problems go to extension dir = "ext" in php.ini and replace ext with the exact path to your ext folder like this:
extension_dir = "C:\Program Files\php7.4.30\ext\"
I have installed Microsoft driver SQLSrv 3.0, installed it, gave the path to php extentions folder. Changed the Php.ini file to include the code
extensions=php_sqlsrv_53_nts_vc9.dll
But when i tried to check whether the drivers loaded by the phpinfo method, The info page doesnot include Sqlsrv section.
I m using Wamp server and windows 7.. php 5.3.6
It means drivers are not loaded. What can be the possible error . Any body help
SQLSRV 3.0 has the Microsoft Native Client 11 as a dependency. This is available for free from Microsoft. (It is also installed when you install SQL Server 2012.)
Try installing SQLSRV 3.0 using the Microsoft Web Platform Installer; that will probably address all of the dependencies for you.
I have a copy of php_memcache.dll (from php_memcache-2.2.6-5.3-nts-vc9-x86.zip) which I have placed in my C:\wamp\bin\php\php5.3.5\ext folder.
In WAMP I can see php_memcache in my extensions list, however whenever I start the extension I get the following warning:
PHP Startup: Unable to load dynamic
library
'C:/wamp/bin/php/php5.3.5/ext/php_memcache.dll'
- The specified module could not be found.
This does not happen for any other extension that I can turn on or off.
Have tried moving php_memcache.dll to C:\windows\system32 but makes no difference.
Any ideas?
Your extension probably not fit the compilation mode of wampserver.
Is it compiled with vc9 (visual 2008) and a non threads safe support ?
My wampserver (latest available) is compiled in VC6 TS.
To know this info check phpinfo() on line :
Compiler
Thread safety
I'd suggest trying other versions of the dll.
2.2.5.0 works for me using WAMP.
The VC9 builds are the only supported builds. VC6 (which is used as convenience builds by Apache) is not supported anymore.
Latest PHP version (and PELC extensions) are only available as VC9 builds. Xamp are already moving their suite to VC9, other already did. You can also do it yourself using apachelounge.com builds, which are the ones we recommend to use with PHP Binaries.