php dblib,错误:SQLSTATE [HY000]未知的主机名(严重性2) [英] php dblib, Error: SQLSTATE[HY000] Unknown host machine name (severity 2)
问题描述
我正在使用Mac计算机OSX 10.9. Freetds和unixODBC已经安装在我的计算机上,并作为扩展名添加到php中,试图连接到远程MSSQL服务器.以下是我的连接测试:
I am using mac computer OSX 10.9. Freetds and unixODBC are already installed on my computer and added as extension to php , trying to connect to a remote MSSQL server. Below is my connection testing:
<?php
$dbh = new PDO('dblib:host=Hostname ;dbname=Dbname', 'user', 'pw');
if (!$dbh) {
die('Something went wrong while connecting to MSSQL');
}
?>
错误日志文件显示:
[error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] Unknown host machine name (severity 2)
可能是什么问题?如果我使用终端连接到相同的数据库,如下所示,我的freetds和unixODBC可以正常工作:
What could be the problem ? It seems that my freetds and unixODBC are working fine if I use terminal to connect to the same database as below:
$ isql Hostname user pw
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
和
$ tsql -S Hostname -U user
Password:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
这是我的freetds.conf
here is my freetds.conf
[global]
# TDS protocol version
tds version = 8.0
[Hostname]
host = IP
port = 1433
tds version = 8.0
client charset = UTF-8 ##needed on MAC OS X
dump file = /tmp/freetds.log
和我的odbc.ini
and my odbc.ini
[Hostname]
#Driver=/usr/local/lib/libtdsodbc.so
Driver = /usr/local/Cellar/freetds/0.91_2/lib/libtdsodbc.so
Trace=No
Server=IP
Port=1433
TDS_Version=8.0
client charset = UTF-8
我的phpinfo()表明已添加了扩展名,PDO部分中有dblib,而pdo_dblib部分中的驱动程序Flavor启用了freetds.
my phpinfo() shows that the extension has been added, there is dblib in PDO section and pdo_dblib section have driver Flavour enabled freetds.
那是什么问题?对我应该做什么有任何想法吗? 任何帮助将不胜感激.
So what is the problem? Any idea of what I should do ? Any assistance will be highly appreciated.
这是我的odbcinst.ini:
here is my odbcinst.ini:
[freetdS]
Description = v0.63 with protocol v8.0
Driver = /usr/local/Cellar/freetds/0.91_2/lib/libtdsodbc.so
推荐答案
我实际上通过删除php扩展文件夹中的mssql.so和pdo_dblib.so来解决此问题,重新下载php5.4,phpize并构建了两者.因此再次归档并放回原处.然后就可以了.
I actually solved this question by deleting both mssql.so, pdo_dblib.so in php extension folder, re-download php5.4 , phpize and build both the .so files again and put it back. Then it works.
似乎我制作的较旧的pdo_dblib.so文件指向其他地方的另一个freetds.conf.
It seems that the olde pdo_dblib.so file I made pointed to a different freetds.conf somewhere else.
这篇关于php dblib,错误:SQLSTATE [HY000]未知的主机名(严重性2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!