SQLSRV in WAMP64 3.1.0 For CLI
Posted by: newmanity (---.eastlink.ca)
Date: April 26, 2018 08:01PM

Hi. On a 64 bit WIndows Server 2012 R2 machine I am using:

- WAMP 3.1.0 (64 bit)
- PHP 7.1.9
- Apache 2.4.27

I have installed sqlsrv because I need to access a MS SQL db from PHP via PDO.
I have thus added the following files to the C:\wamp64\bin\php\php7.1.9\ext directory:

- php_pdo_sqlsrv_71_ts.dll
- php_sqlsrv_71_ts.dll

I have also added the following entries to php.ini:

- extension=php_pdo_sqlsrv_71_ts.dll
- extension=php_sqlsrv_71_ts.dll

Everything works fine from the web browser: phpinfo() displays the sqlsrv drivers and I can establish connections to the DB.

When I run the same scripts via CLI, however, I get an "Uncaught PDOException: could not find driver" error.

I've read that I need to update the php.ini file that is used by CLI, but whereas I'm used to seeing two different php.ini files in older versions of WAMP, there only seems to be one here (while the other is a symbolic link to the one). I'm pulling my hair out trying to figure out what is going on.

When I run php -i from the command line I can see that the sqlsrv driver is indeed not there.

I have noticed that the About section of WAMPSERVER is showing me that whereas Apache is running PHP 7.1.9, it says that PHP 5.6.31 for CLI is being used, which may very well be my problem. But if my batch script explicitly says to use version 7.1.9 (and the -v option response shows me that it is) I don't really know what is going on.

Any help would be very much appreciated.

Thanks

Options: ReplyQuote
Re: SQLSRV in WAMP64 3.1.0 For CLI
Posted by: newmanity (---.eastlink.ca)
Date: April 26, 2018 08:05PM

I should also note that I tried adding C:\wamp64\bin\php\php7.1.9\ to the Windows Path environment variable, but that did not change anything either

Options: ReplyQuote
Re: SQLSRV in WAMP64 3.1.0 For CLI
Posted by: newmanity (---.eastlink.ca)
Date: April 26, 2018 08:31PM

I also just followed the advice at [forum.wampserver.com] to change the Wampserver configs to force CLI to use php 7.1.9 and though it now shows 7.1.9 in the Wampserver about dialog, I get the same error still...

Options: ReplyQuote
Re: SQLSRV in WAMP64 3.1.0 For CLI
Posted by: Otomatic (Moderator)
Date: April 26, 2018 08:44PM

Hi,

Each PHP version located in the wamp64/bin/php/ folder has two php.ini files.
The first one, named "php.ini" is the one that will be taken into account if we use this version in CLI mode.
The second, named "phpForApache.ini" is the one that will be used by the "WEB" PHP version, i.e. the version displayed in the PHP left click. It is used by Apache as a symbolic link named "php.ini" and located in wamp64/bin/apache/apache2.4.27/bin/.
The version declared PHP CLI is the one used by the internal php scripts of Wampserver.

This separation of the two "php.ini" files is made to avoid that an untimely modification of the php.ini WEB blocks the execution of the internal scripts of Wampserver.

Nothing prevents you from using the same PHP version in CLI and in WEB.
A tool allows to change the PHP CLI version:
Right-click -> Tools -> Change PHP CLI version

From this point on, since PHP CLI and PHP WEB are the same version, you can apply the same additional changes and extensions in the "real" php.ini file as you did in the "Apache" php.ini file, that is, in the phpForApache.ini file.
However, do not add the loading of the last section [xdebug].

------------------------------------------------------------------------------------------------------------
Wampserver 3.1.4 32 bit - Apache 2.4.35 - PHP 7.2.11/7.1.23/7.0.32/5.6.38 - MySQL 5.7.23 - MariaDB 10.3.10
Wampserver 3.1.4 64 bit - Apache 2.4.35 - PHP 7.2.11/7.1.23/7.0.32/5.6.38 - MySQL 5.7.23 - MariaDB 10.3.10
PhPMyadmin 4.8.3 - MysqlDumper 1.24.5
on W10 and W7 Pro 64 bit
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons
« Ce n'est pas parce qu'ils sont nombreux à avoir tort, qu'ils ont forcément raison. Coluche »
« It's not because they are many to be wrong, they are necessarily right. Coluche »

Options: ReplyQuote
Re: SQLSRV in WAMP64 3.1.0 For CLI
Posted by: newmanity (---.eastlink.ca)
Date: April 26, 2018 09:07PM

Thanks for the quick feedback, Otomatic.

That is a very confusing change: editing the php.ini file really edits phpForApache.ini ?!

I did not have the "Change PHP CLI version" option in Right-click -> Tools. Is that the right link?

I did, however, just edit the php.ini file in C:\wamp64\bin\php\php7.1.9 (which I thought I was editing this whole time) by adding the extensions and this has solved my issue.

Thanks!!!

Options: ReplyQuote
Re: SQLSRV in WAMP64 3.1.0 For CLI
Posted by: Otomatic (Moderator)
Date: April 26, 2018 09:14PM

Hi,

Apply Update 3.1.3

------------------------------------------------------------------------------------------------------------
Wampserver 3.1.4 32 bit - Apache 2.4.35 - PHP 7.2.11/7.1.23/7.0.32/5.6.38 - MySQL 5.7.23 - MariaDB 10.3.10
Wampserver 3.1.4 64 bit - Apache 2.4.35 - PHP 7.2.11/7.1.23/7.0.32/5.6.38 - MySQL 5.7.23 - MariaDB 10.3.10
PhPMyadmin 4.8.3 - MysqlDumper 1.24.5
on W10 and W7 Pro 64 bit
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons
« Ce n'est pas parce qu'ils sont nombreux à avoir tort, qu'ils ont forcément raison. Coluche »
« It's not because they are many to be wrong, they are necessarily right. Coluche »

Options: ReplyQuote
Re: SQLSRV in WAMP64 3.1.0 For CLI
Posted by: newmanity (---.eastlink.ca)
Date: April 27, 2018 01:49PM

ok...will do. Thanks!

Options: ReplyQuote


Sorry, only registered users may post in this forum.