我试图通过运行在Ubuntu11.04服务器上的PHP连接到SQL数据库。
服务器正在运行PHP5.3.5-1ubuntu7.11版本的=>。
我多次使用apt-get安装了freetds、freetds-php5、tdsodbc、odbcinst、php5-odbc和unixodbc。我试图编译具有SSL支持的FreeTDS,但不确定这是否成功。
此时,当我试图使用isql工具连接时,我会收到一个错误"08S01 -通信链接失败“。微软的一篇文章将此错误解释为“驱动程序与驱动程序试图连接的数据源之间的通信链接在SQLDriverConnect函数完成处理之前失败”。有关这方面的一些研究特别指出,FreeTDS中缺乏SSL支持,但我不清楚如何验证已启用的SSL支持。
我将使用PHP对象或mssql_*函数连接到SQL数据库。我不太熟悉PDO,但似乎PDO不一定使用ODBC?我对此非常不清楚,我怀疑这会导致我对isql所看到的与我在PHP中看到的问题无关的问题进行故障排除。isql工具的连接问题是否与PHP或mssql_*函数中的连接问题有关?
我使用PDO的最新尝试是:
<?php
$c = new PDO("odbc:Driver=FreeTDS;Port=1433;Server=sssssssssss.database.windows.net;Database=db_xxxxx_xxx_xxx;UID=db_xxxxx_xxx_xxx_ExternalWriter;PWD=ppppppppp");
?>此代码在我的Apache日志文件中生成以下错误:
Tue Dec 24 :23:10 2013年客户端10.1.1.11 PHP致命错误:未察觉的异常'PDOException‘,在/var/www/test/pdo.php:3\nStack trace:\n#0 /var/www/test/pdo.php(3):PDO-__ exception (’odbc:Driver=Fre……‘)\n#1{main}中抛入/var/www/test/pdo.php第3行/var/www/test/pdo.php中抛出的消息'SQLSTATE08S01 SQLDriverConnect: 20004 unixODBCSQL ServerRead’
我的/etc/freetds/freetds.conf:
[global]
# TDS protocol version
tds version = 9.1
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
dump file = /tmp/freetds.log
debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
# A typical Microsoft server
[FreeTDS]
host = ssssssssss.database.windows.net
port = 1433
tds version = 9.1
client charset = UTF-8/etc/odbc.ini:
[TS]
Description = "test"
Driver = FreeTDS
Server = sssssssssssss.database.windows.net
Port = 1433
Database = db_xxxxxxx_xxx_xxx/etc/odbcinst.ini
[FreeTDS]
Description = tdsodbc
Driver = /usr/lib/odbc/libtdsodbc.so如果你能帮忙解决这件事,我将不胜感激。很明显我在这一点上迷路了。谢谢!
发布于 2015-07-23 12:34:33
我还没有专门在Azure上尝试过,但是在我们这里的本地SQL Server机器上,我发现php5-sybase模块与PDO相比要容易得多:
apt-get install php5-sybase
<?php
$dsn = 'dblib:dbname=TestDB;host=sqlserver;charset=UTF-8';
$dbh = new PDO($dsn, 'username', 'password');此外,在排除问题时,我发现查看DB通信量的Wireshark跟踪非常有启发性,因为SQL server发出的一些非常有用的消息在PDO错误中没有显示出来。
https://stackoverflow.com/questions/20765344
复制相似问题