Php 如何从PDO连接到SQL Server(dblib)?
世纪7。我已经安装了Php 如何从PDO连接到SQL Server(dblib)?,php,sql-server,pdo,centos,Php,Sql Server,Pdo,Centos,世纪7。我已经安装了 yum install freetds-bin 及 phpinfo中的PDO驱动程序:dblib、mysql、sqlite 具有连接的文件: try { $hostname = "xxx.xxx.xxx.xx"; $port = 1443; $dbname = "MyName"; $username = "test"; $pw = "123456"; $dbh = new PDO ("dblib:host=$hostname
yum install freetds-bin
及
phpinfo中的PDO驱动程序:dblib、mysql、sqlite
具有连接的文件:
try {
$hostname = "xxx.xxx.xxx.xx";
$port = 1443;
$dbname = "MyName";
$username = "test";
$pw = "123456";
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
此页面运行时间很长,最后显示错误500
此文件中的连接出错?或者在MSSQL端对SQL Server的远程访问是否打开不正确?如何理解问题的哪一面?您可以尝试,1)更改为
$dbh=new PDO(“dblib:host=$hostname:$port;dbname=$dbname”,$username,$pw)
(从$username
和$pw
中删除了“”)2)尝试将$hostname
更改为localhost
。如果什么也没发生,请确保所有模块都已正确安装。@Antonis Tsimourtos 1。连接已更改。一切都没有改变。2.我无法指定localhost,因为数据库位于另一台服务器上。但是我试过了。答:无法获取DB句柄:SQLSTATE[HY000]无法连接:Adaptive Server不可用或不存在(localhost:1443)。实际上,您收到的错误消息与此问题有关:可能重复@BOD0谢谢!这个消息是否意味着一切都很好?您可以尝试,1)更改为$dbh=new PDO(“dblib:host=$hostname:$port;dbname=$dbname”,$username,$pw)
(从$username
和$pw
中删除了“”)2)尝试将$hostname
更改为localhost
。如果什么也没发生,请确保所有模块都已正确安装。@Antonis Tsimourtos 1。连接已更改。一切都没有改变。2.我无法指定localhost,因为数据库位于另一台服务器上。但是我试过了。答:无法获取DB句柄:SQLSTATE[HY000]无法连接:Adaptive Server不可用或不存在(localhost:1443)。实际上,您收到的错误消息与此问题有关:可能重复@BOD0谢谢!这个信息是否意味着一切都很好?
try {
$hostname = "xxx.xxx.xxx.xx";
$port = 1443;
$dbname = "MyName";
$username = "test";
$pw = "123456";
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}