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

我怕爱的太早我们不能终老 提交于 2019-11-28 09:15:52

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

This is the generic failure message. You cannot connect to the database for whatever reason. Given you use OSX and brew most likely the problem lies in linking/loading the shared library. FreeTDS is based on Sybase 8 (as is MS SQL Server). It is a bit arcane to compile with.

Was your PHP linked against the libsybdb.dylib that brew installs? You should be able to find out using phpinfo() if this is included in your server:

Configure Command '--with-pdo-dblib=shared,/usr/local/Cellar/freetds/0.91/lib'

To get it to work you need to compile/build your PHP with the dblib option.

Joaquim d'Souza

My solution:

Get FreeTds

  • brew install freetds
  • copy everything in the lib/ folder of your freetds installation into the lib/ folder of your PHP installation directory, replacing the old versions of: libct.4.dylib, libct.a, libct.dylib, libsybdb.5.dylib, libsybdb.a, libsybdb.dylib

Compile and install the dblib extension

  • download the php source for whatever php version you have installed
  • navigate to the ext/pdo_dblib subfolder of the source
  • run phpize, making sure it is the correct binary for your installation
  • run the configure command with e.g. parameters: ./configure --with-php-config=/usr/local/php5/bin/php-config --with-pdo-dblib=/usr/local/Cellar/freetds/0.95.19/
  • run make
  • copy modules/pdo_dblib.so into your PHP installation directory, replacing the old version
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!