【发布时间】:2017-01-09 05:47:42
【问题描述】:
我正在尝试通过我的 php 脚本连接到 Azure Microsoft SQL Server 数据库。我无法弄清楚为什么它不起作用。当我运行我的 db_connection.php 脚本时,我收到了这个错误:
SQLSTATE[01002] Adaptive Server 连接失败(严重性 9)
当我运行 tsql 命令时,带有我的 azure ms sql 数据库的连接详细信息,连接似乎有效(我读到“1>”表示连接有效):
locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "UTF-8"
Default database being set to iBalekaDB
1>
在我的 freetds.conf 文件中,我设置了以下配置:
# server specific section
[global]
# TDS protocol version
tds version = 8.0
text size = 20971520
client charset = UTF-8
dump file = /tmp/freetds.log
debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
[iBalekaServer]
host = xxxxxxxx.xxxxxxx.windows.net
port = 1433
tds version = 8.0
client charset = UTF-8
我的 db_connection.php 文件如下所示:
try {
$dataSource = "dblib:host=iBalekaServer;dbname=iBalekaDB;";
$username = "xxxxxxxxxxxx";
$password = "xxxxxxxxxxxx";
$connectionObject = new PDO($dataSource, $username, $password);
$connectionObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($connectionObject) {
echo "<h2>Connection Successful</h2>";
} else {
echo "Connection Error";
}
} catch (PDOException $e) {
echo $e->getMessage();
}
我在 VPS 上运行 tsql -C 得到了这个:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
我检查了是否安装了 pdo_dblib,当我在我的 Linux VPS 服务器上运行 phpinfo() 时它就存在了。
这可能是什么问题?
编辑:使用 mssql_connect 有效。我真的很想用 PDO
【问题讨论】:
标签: php sql-server azure