I have a Laravel installation running on a Debian 9.9 server and PHP 7.4.
I need to connect to a SQL Server database on a remote Windows server.
I followed this guide to install the PHP extensions:
https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15#installing-the-drivers-on-debian-8-9-and-10
And this one to install the ODBC drivers:
https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15
I also tried reinstalling PHP.
But even after doing all this, I still can’t connect to the database and get this error:
could not find driver
(SQL: select * from [table] where [column] = 123)
Thanks
EDIT
This is are the lines where PDO is mentioned in the result of phpinfo()
PDO support => enabled
PDO drivers => mysql, sqlsrv
pdo_sqlsrv
pdo_sqlsrv support => enabled
ExtensionVer => 5.8.0
Directive => Local Value => Master Value
sqlsrv.ClientBufferMaxKBSize => 10240 => 10240
sqlsrv.LogSeverity => 0 => 0
sqlsrv.LogSubsystems => 0 => 0
sqlsrv.SetLocaleInfo => 2 => 2
sqlsrv.WarningsReturnAsErrors => On => On
php –ini shows that these two extensions are enabled:
/etc/php/7.4/cli/conf.d/pdo_sqlsrv.ini,
/etc/php/7.4/cli/conf.d/sqlsrv.ini
PDO::getAvailableDrivers() returns the following:
Array
(
[0] => mysql
[1] => sqlsrv
)
3
Answers
Turns out the problem was the Apache configuration. Even after reinstalling it, for some reason I had still an old configuration loaded. I had installed the driver on 7.4 and apache was still serving 7.3.
I solved it by doing:
Please try the following, create a php file (ex:
PDO.php
) in some directory and insert the following content into it:then run this file as follows:
Terminal should return an array of available PDO drivers. This way you can check if PHP really has the SQL driver enabled. In my case:
Also check that in the Laravel directory, the
.env
file has correctly configured the connection parameters to the SQL server …I wish you can solve your problem.
* EDIT 1 *
Please try the following:
First, create a file inside the root directory of your web server
(ex: index.php)
, and inside it, insert the following content:access that file through your browser, and it should return all the
php settings
thatapache
is using. Look in thePDO
section, if you have the SQL Server driver loaded ..Debian 9/10
Install Sury APT repository
Install your desired php version
Install additional desired modules (change x.x with version)
For php 7.2:
For php 7.4:
For php 8.0:
Check loaded modules
Or just check sqlsrv
Common trouble:
pecl extension fails because already installed
Just uninstall it:
then try again.