Reputation: 545
I've downloaded and installed drivers in phpext. When I check phpinfo(), figure out drivers installed successfully. But when I use this code to check connection:
$dsn = 'mssql:host=localhost;dbname=chat';
$user = 'sa';
$password = '123';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
This exception appears:
Connection failed: could not find driver Could you please help me?
Upvotes: 0
Views: 3100
Reputation: 2173
You should be using pdo_sql_sqlsrv rather than msssql.
Please make sure that you have the correct sqlsrv extension installed, and that you use an appropriate connection string https://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php
$dsn = 'sqlsrv:host= ....
In many cases when using the sqlsrv extension you will also need to install a compatible version of the sql native client: http://msdn.microsoft.com/en-us/sqlserver/ff658533.aspx
Upvotes: 1