Link to home
Start Free TrialLog in
Avatar of Marthaj
MarthajFlag for United States of America

asked on

Upgrading form PHP 5.6 tp PHP 7.0 and MS SQL Drivers

I am currently upgrading some app from PHP 5.6 to PHP 7.4. My environment is: Wampserver 32, Apache2.4.41, localhost (port 81) on Windows 10 (just until my ubuntu desktop 20,4 is properly installed)'
I had stopped all services, clicked on PHP 7.04, then restarted all  services.
I executed PHPInfo() and everything looks good except I do not have any listing for MS SQL Server.
 I checked the extensions section in the PHP.ini file and this is what it shows:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

; If you wish to have an extension loaded automatically, use the following
; syntax:
;
;   extension=modulename
;
; For example:
;
;   extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
;   extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.
;
extension=bz2
extension=curl
;extension=dba
extension=com_dotnet
;extension=enchant
;extension=ffi
extension=fileinfo
;extension=ftp
extension=gd2
extension=gettext
extension=gmp
extension=intl
extension=imap
extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=phpdbg_webhelper
;extension=shmop

; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=snmp

extension=soap
extension=sockets
;extension=sodium
extension=sqlite3
;extension=sysvshm
;extension=tidy
extension=xmlrpc
extension=xsl
;extension=zend_test

Open in new window

The pathing to PHP7.4 in the php.ini file is correct.
extension_dir ="c:/wamp/bin/php/php7.4.0/ext/"

Open in new window

I also displayed the php extensions from within Wampserver. I see curl and sqllite and etc, But nothing I recognize for MS SQL Server. Andam wondering also about the construction of making my MS SQl DB connection, 
What am I missing and what do I need to do to correct this ??
Any help is appreciated and thank you in advance.



Avatar of Andrei Fomitchev
Andrei Fomitchev
Flag of United States of America image

I think that access of MS SQL Server requires extension for PHP7. You can read about it here:
https://x-team.com/blog/using-ms-sql-dynamic-ports-in-php-7-with-odbc/
Avatar of Marthaj

ASKER

I believe I am missing the following PDO drivers: And have not located where they are to download
I am using  MS SQL SEVER 2014 (I think)I did find the PDO_SQLSRV -  extracted files - there were 4 of them. And copied them the ext folder for PHP 7.4
I don't know  if I down-loaded the right ones - but according to Microsoft chart - I selected SQLSRV58.exe.I added them to my php.ini file- re-booted my computer and I have attached a screen shot of it too.  rebooted my computer and checked the PHP extensions loaded and they were checked marked.
I executed phpinfo.php  and have attached an screen shot of  it. There were no  errors in the PHP Error log. And I think I read that there were only 4 PDO files for MS SQL Server. But I am wondering if I should load the PDO-odbc ext. Opinion ??

User generated image
User generated image

For the remaining two ,  PDO_DBLIB is depreciated in PHP 7.4 and PDO_DBLIB_DSN is for Sybase.
If I am doing anything wrong, please correct me.
Any help is appreciated.

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The reason for the four files is first you have to select 32 or 64 bit. If you are on windows10, search, 'about' in the windows search box.  It will show under System Type if you are on 64 or 32 bit.  And the other two options are thread-safe or non-thread-safe. For windows, you want nts.  

For a 64 bit machine, select nts_x64.dll.  
For a 32 bit machine, select the nts_x86.dll
There are several changes going from pre-PHP-7.X to PHP-7.X where are...

1) A few extensions have moved from PHP core to external .so files, so you're installation process will be similar to this...

Note: I use Linux, as WAMP... is for rich people with massive extra time on their hands... :-)

Here are the Ubuntu commands, which you'll have to... transcribe to... accomplishing on Windows... which will shortly become a full time job for someone, just to keep up with finding all LAMP + OpenSSL updates, building from source, installing...

# Ensure all PPA/Repository code management tools are installed...
apt-get install software-properties-common

# Setup all latest stable LAMP Stack PPAs...
LC_ALL=C.UTF-8 add-apt-repository ppa:mamarley/updates </dev/null
LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/apache2 </dev/null
LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php </dev/null
LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/nginx-mainline </dev/null
LC_ALL=C.UTF-8 add-apt-repository ppa:isc/bind-dev </dev/null
LC_ALL=C.UTF-8 add-apt-repository ppa:jonathonf/vim </dev/null

# Special PPA setup for latest MariaDB, which delivers hotfix code faster than Debian/Ubuntu
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --skip-maxscale

# Usually this next isn't required anymore + I do this just to make sure...
apt-get update

# Install MariaDB, making sure latest stable installs...
apt-get install mariadb-server-10.5 mariadb-client-10.5 libmariadb-dev-compat

# Install latest PHP (today PHP-7.4.20.1)
apt-get install php7.4-dev php7.4-fpm php7.4-xdebug php7.4-cli php7.4-mbstring php7.4-zip \
                php7.4-mysql php7.4-curl php7.4-imap libphp7.4-embed \
                php7.4-xml php7.4-xmlrpc php7.4-gd php7.4-soap \
                php7.4-sqlite3 php7.4-tidy php7.4-xsl php7.4-bz2 php7.4-gmp \
                php7.4tidy php7.4-bcmath php7.4-bz2 php7.4-dba php7.4-pspell \
                apache2 apache2-dev logtop nghttp2-client

# Ensure php cli at correct version
update-alternatives --set php /usr/bin/php7.4

# Disable all monolith Apache code
a2dismod mpm_prefork cgi

# Enable all threaded + HTTP2 supportive Apache code
a2enmod mpm_event proxy_fcgi setenvif alias cgid ssl http2 expires headers include rewrite brotli
a2enconf php7.4-fpm

# Hard restart, to drop any monolithic code running, replacing with threaded + HTTP2 supportive code...
service php7.4-fpm restart
service apache2 restart

# Anytime you'd like to upgrade all your LAMP Stack code
apt-get update && apt-get upgrade

Open in new window


2) PHP has moved from monolith code (libapache2-mod-php) to FPM (proxied PHP).

This move was made, so mpm_event + mod_http2 can be used together to implement HTTP2 in Apache + PHP.

Under WAMP, you can't implement HTTP2 at all, because you can only use mpm_winnt which last time I checked, provides no support for the mod_http2.

So if you require HTTP2, you'll use a LAMP Stack instead.

3) Now that you have all latest LAMP Stack + OpenSSL code running, it's time to deal with version incompatible source code changes.

You'll do this mechanically with phpcs (find changes) and phpcbf (auto fix many changes).

The phpcs suite is very smart, even reordering mysql API calls, when required, going from PHP-5.6 -> PHP-7.X or above.

# Where all PHP Comptibility code will live - ~/php-code-sniffer
mkdir ~/php-code-sniffer && cd ~/php-code-sniffer

# Clone the Github project code
git clone https://github.com/squizlabs/PHP_CodeSniffer.git PHP_CodeSniffer.git
git clone https://github.com/wimg/PHPCompatibility.git PHPCompatibility.git

# Optionally add PHP Syntax checking, which is highly useful...
# Refer to - https://github.com/squizlabs/PHP_CodeSniffer/issues/2930 - for syntax checking

# Add inside your ~/.bashrc + crontab -e the phpcs path, however you do this.
# Then be sure you re-source your ~/.bashrc file to pull in phpcs path
PATH=$PATH:~/php-code-sniffer/PHP_CodeSniffer.git/bin

# This should work now
which phpcs phpcbf

# Setup Coding Standard packs
phpcs -d xdebug.show_exception_trace=0 --config-set installed_paths ~/php-code-sniffer/PHPCompatibility.git
phpcs -d xdebug.show_exception_trace=0 --config-show installed_paths

# Both phpcs + phpcbf should now show these set - Zend, PSR2, PEAR, Squiz, PSR1, MySource and PHPCompatibility
phpcs -d xdebug.show_exception_trace=0 -i
phpcbf -d xdebug.show_exception_trace=0 -i

# Now run phpcs using --parallel=$you-cpu-thread count, to rapidly analyze 1000s of files/second...
nice -19 phpcs -d xdebug.show_exception_trace=0 -p --parallel=16 --standard=PHPCompatibility \
     --encoding=utf-8 --extensions=php,inc,lib,js,css,html --runtime-set testVersion 7.3 \
     /path-to-files-to-check > ~/app-php-5.6-tofix.txt 2>&1

Open in new window


4) After your phpcs run, you can use phpcbf to auto fix most reported problems.

Also fix every warning, as PHP-8.0 will promote many warnings to hard failures.

My rule, only deploy PHP code which runs silently, no diagnostic (errors/warnings/any) messages... ever... period...

5) This will be a daunting project to complete under WAMP.

Using Ubuntu Focal, this takes a few minutes to get to a point of phpcs running.
This will be a daunting project to complete under WAMP.

Pay no attention to this man's rhetoric. I run PHP locally, using iis with mssql server 2019 and my server is also windows with SQL server.  It is no more complicated than anything else PHP or web dev....but it works.

One thing I caught in the file you posted
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.

Open in new window

Make sure those dll's are in the correct folder. I don't know how WAMP works, but I put all the dll's in the ext folder C:\php\7.4\ext
Avatar of Marthaj

ASKER

Thank you all for your responses. It is appreciated as is your help.

Julian/Scott -   thank you for the link and for your responses - since my last posting, I had read the article and I remembered from when I first loaded PHP 5.6, I had to download the  correct drivers, place in the ext folder (C:\php\5.6\ext ,then either uncomment or add an line referencing the extension in the php.ini file and restart Apache would load the extensions. They would show that they were loaded and executed phpinfo().  That being so and from what I read, I used the same process for the PHP 7.4 extensions. And after restarting Apache, it shows they are loaded. so I think I am okay there and should be able to use them. And my phpinfo() shows pdo_sqlsvr loaded. That being so, I would think I was okay. I will find out  when I modify the SQL statements. It's just been a very long time. I do know that I need to change my connection type to be an ODBC connection and that is the next step. No clue on that one  construction of that to connect but will research it and make sure I uncomment the driver in the php.ini file etc.

Scott - what are you using instead of Wampserver ? - just wondering..

Andrei - a good link too - helpful - thank you

David - and thank you too for responding but it went over my head right now.. And  your posting is something for my Ubuntu OS. I have already successfully installed PHP 7.4 on it, but now dealing with setting up multiple web sites under .var/www and creating virtual hosts so I don't have to constantly re-edit  the config files changing the DocumentRoot statement when I want to work with a different website,  

I see no reason why I can not upgrade the apps using Wampserver executing PHP 7.4 - it will be a matter of changing the syntax of the SQL statements and of course including the connection to the MS SQL Server. In my mind, it's no different, other than drivers and construction of the SQL statements and etc. The client already has PHP 7.4 apps executing on the Ubuntu server, But I don't know how they connecting - and after reading, I would hedge my bet they are using ODBC. I am still waiting on a response from client about this information.
The whole end-purpose  is to upgrade to PHP 7.4 and then eventually use Ubuntu Desktop 20.4 to develop the applications so I am mirroring  their production server as much as possible. But, until I have a better handle on the Ubuntu OS, I will do the upgrade to PHP 7.04 on the Windows platform, I already know I will have problems with deleting files from within the code, but that is what start this whole situation. I changed the flow of the app which allows me to wait to the end of app to delete the files. Made it faster. And if the files  don't delete, it won't  mess with my test results and cause a ripple effect. And a shell call can be made to delete them.
Opinions ??
 what are you using instead of Wampserver ?  

I just loaded IIS on my windows 10 machine.  I have two laptops. One I think I installed by using add/remove windows features in the control panel and the other I may have used the web platform installer https://www.microsoft.com/web/downloads/platform.aspx   And MSSQL and MySql installed separately.

With the way the internet connects are, it is also just as easy to RDP into a remote server like it is in the same room. So using a VPN to RDP to a dev server is what I mostly use.



All of the current drivers for SQLSRV are here:  https://github.com/microsoft/msphpsql
Also information on the different systems that it can run on.
Hi,

I'm using Wampserver since many years.
First you will need to update the entire Wampserver not just PHP version.
I did it a few times.

I have not tested for MS SQL
But you can try donwload https://www.microsoft.com/en-us/download/details.aspx?id=20098
Extract the application and add the path C:\wamp64\bin\php\php7.0.23\ext
(change the PHP version with the one you are using)
Then for all others steps you can check
http://eecs.csuohio.edu/~sschung/CIS408/MSSQLServerConnectedWAMPInstruction.pdf
Avatar of Marthaj

ASKER

Thank you all for responding.
Julian, the link you provide set me on the right path - never lose that link !
I  was able to coordinate my environment - download/load the correct dlls to successfully establish a  SQL connection using PHP 7.4. The connection is slow.
I also had to upgrade my SQL Server from 2008 to 2014 since there was no MS drivers available for 2008 running  for PHP 7.4. Since both php_pdo_sqlserv_74.ts_x86.dll and php_dqldrv_74_ts_x86.dll, I can use structure my coding to use pdo or not. Would that be correct. I also read (somewhere) the php_pdo_sqlserv_74.ts_x86.dll did not work right or was depreciated.
This is what I added to the extension listings in php.ini file
extension=php_pdo_sqlsrv_74_ts_x86.dll
extension=php_pdo_sqlsrv_74_nts_x86.dll
extension=php_sqlsrv_74_nts_x86.dll
extension=php_sqlsrv_74_ts_x86.dll

Open in new window

And my phpinfo is correct as to the dlls were loaded.
I do receive an error message in my php_error log:
[14-Jun-2021 17:12:28 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_74_nts_x86.dll' (tried: c:/wamp/bin/php/php7.4.0/ext/php_pdo_sqlsrv_74_nts_x86.dll (The specified module could not be found.), c:/wamp/bin/php/php7.4.0/ext/php_php_pdo_sqlsrv_74_nts_x86.dll.dll (The specified module could not be found.)) in Unknown on line 0

Open in new window

Yet, when I check  the listings of  php extensions (Wampserver) , they show as being loaded....
I did not set the extension directory as the default directory is suppose to be automatically set to:
c:/wamp/bin/php/php7.4.0/ext/

Open in new window

Where is the done at ? I search the php.ini file and did not find it listed, only comment references to it.
Thank you for responding - much good input. I wish I could give you 'my solutions' because each one did help.
But the link Julian provided gave me the road map to follow.
If any of you are not satisficed, please contact me we can discuss it.
I liked the old way of being able to split points. Things change.
 





For windows you want to use the non-thread-safe version  php_pdo_sqlsrv_74_nts_x??   I wouldn't enable both.  

Also, are you sure your machine is 32 bit (x86.dll) and not 64bit (x64.dll)

I personally just stick with pdo.


@Scott Fell, that's not right.  IIS requires 'nts' versions and Apache requires the 'ts' versions.
Thank you for the clarification. I just always use iis and was about to follow up on that point.