我正在尝试通过在Ubuntu 11.04服务器上运行的PHP连接到SQL Azure数据库。
服务器正在运行PHP Version => 5.3.5-1ubuntu7.11。
我已经多次使用apt-get install安装了freetds-bin,freetds-common,tdsodbc,odbcinst,php5-odbc和unixodbc。我尝试使用SSL支持编译FreeTDS,但不确定是否成功。
此时,尝试使用isql工具进行连接时收到错误“08S01 - 通信链接失败”。 Microsoft文章将错误解释为“在SQLDriverConnect函数完成处理之前,驱动程序尝试连接的驱动程序和数据源之间的通信链接失败”。一些研究特别指出FreeTDS中缺乏SSL支持,但我不清楚如何验证已启用。
我将使用PHP Data Objects或mssql_ *函数连接到SQL Azure数据库。我对PDO不熟悉,但似乎PDO不一定使用ODBC?我很不清楚这一点,我怀疑这是导致我解决isql看到的与我在PHP中遇到的问题无关的问题。使用isql工具的连接问题是否与PHP中的PDO或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 13:23:10 2013] [error] [client 10.1.1.11] PHP致命错误: 带有消息'SQLSTATE [08S01]的未捕获异常'PDOException' SQLDriverConnect:20004 [unixODBC] [FreeTDS] [SQL Server]从中读取 服务器失败'在/var/www/test/pdo.php:3 \ nStack trace:\ n#0 /var/www/test/pdo.php(3):PDO-&gt; __ construct('odbc:Driver = Fre ...')\ n#1 {main} \ n在第3行的/var/www/test/pdo.php中抛出
我的/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
对此混乱的任何帮助都将非常感激。在这一点上,我显然已经迷失了。谢谢!
答案 0 :(得分:0)
我没有特别尝试使用Azure,但是在我们这里的本地SQL Server机器上,我发现带有PDO的php5-sybase模块比freetds更容易使用:
apt-get install php5-sybase
<?php
$dsn = 'dblib:dbname=TestDB;host=sqlserver;charset=UTF-8';
$dbh = new PDO($dsn, 'username', 'password');
此外,在解决问题时,我发现将Wireshark的数据流量跟踪视为具有启发性,因为SQL服务器通常会发出非常有用的消息,而这些消息不会在PDO错误中消失。