1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Perra
  • 44
  • 2
  • 7
  • Check this - http://stackoverflow.com/questions/41624704/sql-server-pdo-could-not-find-driver – Suresh May 16 '17 at 10:11

1 Answers1

-1

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.

Community
  • 1
  • 1
Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
  • i followed the steps but i still got the same error. I tried this in wamp and xampp. followed multiple tutorials with no positive result. – Perra May 19 '17 at 10:53