• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question how to install MS SQL drivers for PDO

Butcher

New Pleskian
I am trying to connect to MS SQL from php

I use:
PHP:
$conn = new PDO("dblib:Server=$serverName;Database=$base", "$user", "$pass");

but it seems that my server is missing PDO DRIVER, I only have:
PDO driversmysql, odbc, pgsql, sqlite

and I got:
PHP:
Got error 'PHP message: PHP Fatal error:  Uncaught PDOException: could not find driver in /var/www/vhosts...

so how to get the driver for PHP 7.0.3 at the moment ?

I tried: Pecl install sqlsrv returns No releases available for package

and it teoritically got installed but no effects
 
When I do Step 4 from: Linux and macOS Installation for the Drivers for PHP - PHP drivers for SQL Server
You can alternatively install from the Remi repo:
Bash:
sudo yum install php-sqlsrv


I got:
Bash:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                 |  26 kB  00:00:00     
 * base: ftp.icm.edu.pl
 * epel: epel.mirror.serveriai.lt
 * extras: ftp.icm.edu.pl
 * updates: ftp.icm.edu.pl
PLESK_17_PHP56                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP70                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP71                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP72                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP73                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP74                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP80                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP81                                                                                                       | 2.9 kB  00:00:00     
PLESK_17_PHP82                                                                                                       | 2.9 kB  00:00:00     
PLESK_18_0_52-extras                                                                                                 | 2.9 kB  00:00:00     
base                                                                                                                 | 3.6 kB  00:00:00     
epel                                                                                                                 | 4.7 kB  00:00:00     
extras                                                                                                               | 2.9 kB  00:00:00     
plesk-ext-panel-migrator                                                                                             | 2.9 kB  00:00:00     
plesk-ext-ruby                                                                                                       | 2.9 kB  00:00:00     
plesk-ext-site-import                                                                                                | 2.9 kB  00:00:00     
updates                                                                                                              | 2.9 kB  00:00:00     
(1/2): epel/x86_64/updateinfo                                                                                        | 1.0 MB  00:00:00     
(2/2): epel/x86_64/primary_db                                                                                        | 7.0 MB  00:00:00     
No package php-sqlsrv available.
 
I tried with PECL:
Bash:
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
pecl/sqlsrv requires PHP (version >= 8.0.0), installed version is 7.3.33
 
CentOS is based off of Red Hat Linux, so you follow the instructions for that.

Bash:
sudo su
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm subscription-manager repos --enable=rhel-7-server-optional-rpms yum install yum-utils yum-config-manager --enable remi-php81 yum update # Note: The php-pdo package is required only for the PDO_SQLSRV driver
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo su
echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini
echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini
exit

I do not know what version of CentOS you're using but I'm going to assume it's 7 which those steps are for.

Also if you're using PHP 7.0.x, I would highly recommend that you update your code to support the latest 7.4 but tbh even to that I would recommend bringing your code to at least 8.1 since PHP is no longer supporting older PHP releases and is going to become harder and harder to find proper support just a fyi.
 
CentOS is based off of Red Hat Linux, so you follow the instructions for that.

Bash:
sudo su
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm subscription-manager repos --enable=rhel-7-server-optional-rpms yum install yum-utils yum-config-manager --enable remi-php81 yum update # Note: The php-pdo package is required only for the PDO_SQLSRV driver
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo su
echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini
echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini
exit

I do not know what version of CentOS you're using but I'm going to assume it's 7 which those steps are for.

Also if you're using PHP 7.0.x, I would highly recommend that you update your code to support the latest 7.4 but tbh even to that I would recommend bringing your code to at least 8.1 since PHP is no longer supporting older PHP releases and is going to become harder and harder to find proper support just a fyi.
Thank you.

Yes, it's CentOS7.
What I did is move to PHP 8 with project - checking if everything works as it should right now. There was no problems with sqlsrv in PHP8.
When it comes to PHP 7.0.X or 7.4 I got some ERRORS all the time when trying to make it work.

I know it is probably subject for different discussion but what you think of using Alma instead of CentOS?
 
Back
Top