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

问题描述

我连接到外部MSSQL数据库以从PHP55 / osx导出,我有wierd问题。



代码: >

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

throws

  SQLSTATE Adaptive Server连接失败(严重性9)

但来自CLI的连接正确无误



tsql -S主机名-U用户-P pass -L dbname

  locale是cs_CZ.UTF-8
区域设置字符集是UTF-8
使用默认字符集UTF- 8
1>

freetds.conf

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



tsql -C:

 版本:freetds v0.91 
freetds.conf目录:/usr/local/Cellar/freetds/0.91/etc
MS db-lib源兼容性:no
Sybase二进制兼容性:没有
线程安全:是
iconv库:是
TDS版本:7.1
iODBC:no
unixodbc:no
SSPItrustedlogins:no
Kerberos:no

任何想法?我已经尝试过任何东西,连接到主机名,ip,有和没有端口,实例名,另一个用户,TDS版本7.0,7.1,7.2,8.0,重新安装php和freetds

解决方案

查看这些:


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


  2. 旁边的〜/ .freetds.conf,全局]部分在你的freetds.conf文件。放置这些行:



    tds version = 8.0



    文字大小= 20971520



    client charset = UTF-8


当然,该驱动程序由phpinfo()加载PHP:mssql,sqlsrv或dblib


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

code:

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

throws:

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

but connection from CLI works correcty

tsql -S hostname -U user -P pass -L dbname:

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

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

解决方案

Check these:

  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/

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

    tds version = 8.0

    text size = 20971520

    client charset = UTF-8

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

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

08-28 15:24