【问题标题】:Having trouble with sqlsrv on CentOS 7. Looking for assistance or possibly ODBC alternative在 CentOS 7 上遇到 sqlsrv 问题。寻求帮助或可能的 ODBC 替代方案
【发布时间】:2016-06-23 19:21:21
【问题描述】:

我正在尝试在 Linux 系统上使用 PHP 连接到 MSSQL DB。

使用tsql -S <dbConfig>tsql -H <dbHost> 成功连接到数据库(当然是使用用户凭据)。但是,在 PDO 中使用相同的主机和配置会返回连接到主机适配器失败的错误。

问题似乎存在于 PHP PDO 和我假设是 freetds 之间。

调试看起来像这样:

 PDOException in Connector.php line 55:
 SQLSTATE[01002] Adaptive Server connection failed (MYHOST.database.windows.net) (severity 9)
        in Connector.php line 55

at PDO->__construct('dblib:host=MYHOST.database.windows.net;dbname=RecipeDB;charset=utf8', 'MYUSER@MYHOST', 'MYPASSWORD', array('0', '2', '0', false)) in Connector.php line 55
at Connector->createConnection('dblib:host=MYHOST.database.windows.net;dbname=RecipeDB;charset=utf8', array('driver' => 'sqlsrv', 'host' => 'MYHOST.database.windows.net', 'database' => 'RecipeDB', 'username' => 'MYUSER@MYHOST', 'password' => 'MYPASSWORD', 'charset' => 'utf8', 'prefix' => '', 'name' => 'remoteRecipes'), array('0', '2', '0', false)) in SqlServerConnector.php line 32
at SqlServerConnector->connect(array('driver' => 'sqlsrv', 'host' => 'MYHOST.database.windows.net', 'database' => 'RecipeDB', 'username' => 'MYUSER@MYHOST', 'password' => 'MYPASSWORD', 'charset' => 'utf8', 'prefix' => '', 'name' => 'remoteRecipes')) in ConnectionFactory.php line 61
at ConnectionFactory->Illuminate\Database\Connectors\{closure}()

【问题讨论】:

    标签: php sql-server pdo sqlsrv php-5.6


    【解决方案1】:

    看来我已经设法从 /etc/freetds.conf 文件中删除了包含 [global] 的行。一旦我替换它,PDO 就能够调用数据库。

    下面是我的样子:

    [global]
    # TDS protocol version
     ; tds version = 4.2
     tds version = 8.0
     client charset = UTF-8
    
    # 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
    
    [testConnection]
        host = MYHOST.database.windows.net
        port = 1433
        tds version = 8.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-08
      • 2021-10-17
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 2021-11-13
      • 2010-11-21
      相关资源
      最近更新 更多