0

I would like to connect to my database which is on an SQL Server, but to do so I need to specify several items including a sid. I don't understand where my error comes from, but when I run my code I get the following error:

"Error: could not find driver".

Can you help me?

<?php

$bdName = "bdname";
$username = "username";
$password = "mdpname";
$host = "remotehost";
$port = 1521;
$sid = "mysid";

$dsn = "sqlsrv:dbname=".$bdName."//".$host.":".$port."/".$sid;
try {
    $bdd = new PDO($dsn,$username,$password);
    //echo "<p> Connexion OK </p>";
} catch (PDOException $e) {
    echo "<p> Erreur Connexion </p>";
    print "Erreur !: " . $e->getMessage() . "<br/>";
    die();
}

Zhorov
  • 25,115
  • 5
  • 19
  • 43
  • 4
    Do you have the SQL driver/extension installed and enabled? https://www.php.net/manual/en/ref.pdo-sqlsrv.php – Chris Haas May 29 '22 at 14:40
  • 1
    Note that port 1521 is the default port number for Oracle. The SQL Server default port number is 1433. See [this answer](https://stackoverflow.com/questions/12747554/connect-to-sql-server-through-pdo-using-sql-server-driver) for a PDO example. – Dan Guzman May 29 '22 at 15:33

0 Answers0