简体   繁体   English

使用pdo连接到php中的mssql时找不到驱动程序

[英]Couldn't find driver when use pdo to connect to mssql in php

I've downloaded and installed drivers in phpext. 我已经在phpext中下载并安装了驱动程序。 When I check phpinfo(), figure out drivers installed successfully. 当我检查phpinfo()时,找出成功安装的驱动程序。 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? 连接失败:找不到驱动程序,请您能帮我吗?

You should be using pdo_sql_sqlsrv rather than msssql. 您应该使用pdo_sql_sqlsrv而不是msssql。

Please make sure that you have the correct sqlsrv extension installed, and that you use an appropriate connection string http://ie2.php.net/manual/en/ref.pdo-sqlsrv.connection.php 请确保您安装了正确的sqlsrv扩展名,并且使用了适当的连接字符串http://ie2.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 在许多情况下,使用sqlsrv扩展时,您还需要安装sql本机客户端的兼容版本: http : //msdn.microsoft.com/zh-cn/sqlserver/ff658533.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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