简体   繁体   中英

PDO Error: could not find driver (SQL Server connect)

I'm trying to connect to my azure sql server database using PDO. But my code gives an error.

Error: could not find driver

My code:

$conn;
try {
    $conn = new PDO("sqlsrv:Server=perslegt.database.windows.net,1433;Database=products", "serveradmin@perslegt", 'password');
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}
function dbClose(){
    $conn = null;
}

I already allowed the ip addresses 000.000.000.000 to 255.255.255.255 in the firewall. But it gave the same error.

Basically, to access Microsoft SQL Server or SQL Azure databases in PHP, we need to install the SQLSRV extension first. If your PHP application runs on Windows, you can find step by step installation instructions here and here .

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