PHP PDO_mssql SQLSTATE[01002] Adaptive Server 连接失败(严重性 9) [英] PHP PDO_mssql SQLSTATE[01002] Adaptive Server connection failed (severity 9)

查看:21
本文介绍了PHP PDO_mssql SQLSTATE[01002] Adaptive Server 连接失败(严重性 9)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在连接到外部 MSSQL 数据库以从 PHP55/osx 导出,但遇到了奇怪的问题.

I'm connecting to external MSSQL database for exports from PHP55/osx and I have wierd issue.

代码:

new PDO("dblib:host={$hostname};dbname={$dbname}", $user, $pass);

抛出:

SQLSTATE[01002] Adaptive Server connection failed (severity 9)

但来自 CLI 的连接工作正常

but connection from CLI works correcty

tsql -S 主机名 -U 用户 -P pass -L 数据库名:

locale is "cs_CZ.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> 

freetds.conf:

[hostname]
    host = ipaddress
    port = 1433
    tds version = 8.0

tsql -C:

                        Version: freetds v0.91
         freetds.conf directory: /usr/local/Cellar/freetds/0.91/etc
 MS db-lib source compatibility: no
    Sybase binary compatibility: no
                  Thread safety: yes
                  iconv library: yes
                    TDS version: 7.1
                          iODBC: no
                       unixodbc: no
          SSPI "trusted" logins: no
                       Kerberos: no

有什么想法吗?我几乎尝试过任何东西,连接到主机名、IP、带和不带端口、实例名称、另一个用户、TDS 版本 7.0、7.1、7.2、8.0,重新安装 php 和 freetds

Any ideas? I have tried alomost anything, connect to hostname, ip, with and without port, to instance name, another user, TDS versions 7.0,7.1,7.2,8.0, reinstall php and freetds

推荐答案

检查这些:

  1. 在您的磁盘上找到 freetds.conf.它可能存在于多个地方,tsql 使用一个,而 PHP 使用另一个.最好的方法是将它们符号链接到一个公共文件中并对其进行测试.请注意,该文件的常见位置是/etc/或/usr/local/etc/旁边的 ~/.freetds.conf

  1. locate freetds.conf on your disk. It is possible it exists in several places and tsql uses one while PHP used another one. Best is to symlink them into one common file and test on that. Note that a common place for that file is ~/.freetds.conf beside /etc/ or /usr/local/etc/

在您的 freetds.conf 文件中应该有一个 [global] 部分.把这些行放在那里:

there should be a [global] section on your freetds.conf file. Put there these lines :

tds 版本 = 8.0

tds version = 8.0

文字大小 = 20971520

text size = 20971520

客户端字符集 = UTF-8

client charset = UTF-8

当然,我希望您已经使用 phpinfo() 检查过 PHP 加载了哪个驱动程序:mssql、sqlsrv 或 dblib

Of course, I expect that you already checked which driver is loaded by PHP with phpinfo(): mssql, sqlsrv or dblib

这篇关于PHP PDO_mssql SQLSTATE[01002] Adaptive Server 连接失败(严重性 9)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆