Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

niheno's avatar

Problems with Microsoft SQL PDO driver (PDOException)

I want to connect to a Microsoft SQL server instance that is hosted on my Windows machine from a ubuntu 16.04 virtual machine. I've installed sqlsrv and pdo_sqlsrv according to https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac

artisan migrate works, but when my application tries to access the database through the pdo driver (for example when trying to register) it throws a QueryException saying

could not find driver

The error page also shows that it is a PDOException.

How can I go about fixing this?

0 likes
7 replies
niheno's avatar

Yes I installed the ODBC driver.

pdo_sqlsrv and sqlsrv don't show up in phpinfo(), but artisan can use the connection (which is defined as sqlsrv in .env)

Helmchen's avatar

make a phpinfo() file, scroll down to PDO Support - PDO drivers .. does that include the proper driver?

Helmchen's avatar

but you have loaded the .so files right?

echo "extension=sqlsrv.so" >> /etc/php/7.X/apache2/php.ini
echo "extension=pdo_sqlsrv.so" >> /etc/php/7.X/apache2/php.ini

these guys, especially the pdo_* one

restart apache afterwards - afaik they should show up there

lostdreamer_nl's avatar

be advised : You have 2 php.ini files, one for the command line interface and one for the webserver (probably fpm)

It might be that it is setup on the cli/php.ini but not on the fpm/php.ini

Check the output of phpinfo() to see the location of the webserver php.ini file and make sure the driver is added in there as well.

Please or to participate in this conversation.