PHP Sql Server PDOException:could not find driver-ThrowExceptions

Exception or error:

My server is a Windows 2008 server. PHP Version 7.2.7 is installed and running. Sql Server 11 (64 bit) is installed and is working (there is a couple apps running and already using that database)

I downloaded the PHP Sql Server Drivers from Microsofts website and placed the .dll files in the PHP ext directory.

In my PHP.ini I added:extension=php_pdo_sqlsrv_7_nts_x64

In my .php file I am using to test my db connection I have:

 $SqlServerCon = new PDO("sqlsrv:server=$SqlServer;Database=TheDatabase", "DbUName", "DbPassword"); 
if (!$SqlServerCon) {die('Unable To Connect to Sql Server');}
{echo "Connection Successful";}     

I am getting:
PHP Fatal error: Uncaught PDOException: could not find driver in D:\Inetpub\wwwroot\TechStory2\DBtest.php:7 (Line 7 is the $SqlServerCon line).

What did I do wrong? and What do I need to do to get a connection to Sql Server?

How to solve:

I got it figured out. I had to install the ODBC Driver 17 for SQL Server (msodbcsql_17.2.0.1_x64.msi) on my server. The SQL Server Native Client 11.0 was installed but not the ODBC Driver for SQL Server.

For future reference for anyone else with this or a similar issue…

It can be downloaded at (note: if you have a 32 bit server, you will want to install the msodbcsql_17.2.0.1_x86.msi – If you accidentally try to install the incorrect version, it will let you know during the installation). After the driver is installed, you need to reboot the server. It won’t prompt you to restart, but you’ll need to.

In my PHP.ini I have added extension=php_pdo_sqlsrv_72_nts.dll and extension=php_sqlsrv_72_nts_x64.dll They can be downloaded at

More info can be found at and

I can now establish a connection to Sql Server using either sqlsrv_connect or PDO.

PDO connection test:

$SqlServerCon = new PDO("sqlsrv:server=$SqlServer;Database=TheDatabase", "DbUName", "DbPassword"); 
if (!$SqlServerCon) {die('Unable To Connect to Sql Server');}
{echo "Connection Successful";} 

sqlsrv_connect connection test:

$DbConnInfo = array( "Database"=>"TheDatabase", "UID"=>"DbUName", "PWD"=>"DbPassword");
$SqlServerCon = sqlsrv_connect( $SqlServer, $DbConnInfo);
if( $SqlServerCon ) {echo "Connection established";}
{echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));}


As commentators said – adding .dll at the end of extension= config line should be good start with your issue.

I can also see that you’re trying to load NTS version of extension (NTS stands for non thread safe). Are you sure that you’re going to load right version of extension? Please check if you’re running PHP as NTS runtime or not – you can check it with phpinfo();.

Leave a Reply

Your email address will not be published. Required fields are marked *