简体   繁体   中英

When trying to connect to a Azure SQL server i get a PDOException could not find driver

Im trying to connect to a Azure SQL server but get the following exception: PDOException Object ( [message:protected] => could not find driver

After some research i found that most people run into this problem when the pdo_mysql extension isnt activated in their php.ini So i checked my php.ini file but i already enabled it and it works otherwise Laravel wouldnt work for my other projects. Then i found out that you have to check your phpinfo(). But when checking my phpinfo i can see that the driver is installed.

I am trying to connect to the SQL server using the following PHP code:

$sqlServer = "tcp:server.database.windows.net,1433";
$sqlUser = "admin@server";
$sqlPwd = "password";
$sqlDb = "database";
$sqlDsn = "sqlsrv:Server=$sqlServer;Database=$sqlDb";

try {
    $conn = new PDO($sqlDsn, $sqlUser, $sqlPwd);
    $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch (PDOException $e) {
    die(print_r($e));
}

for asking this question i've changed the credentials, i've triple checked and the credentials i'm using are correct.

Can someone help me figure out why i get the driver exeption?

Could you please make sure you have installed this driver?

After that make sure you have enable it on php_ini by adding the line:

extension=php_pdo_sqlsrv_72_nts.dll

After that please restart Apache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM