php - 使用 Zend Framework 2 和 ODBC 驱动程序连接忙于 Linux 上的 MS SQL Server

标签 php sql-server linux zend-framework2 pdo-odbc

我需要将 Windows 服务器设置迁移到 Linux (Red Hat 7.2) 服务器。以前我们在 Windows 机器上使用 pdo_sqlsrv 驱动程序。在 Linux 上,我们安装了 pdo_odbc 驱动程序。但是由于 Zend Framework 2 不支持开箱即用,我自己使用 ZF2 API 文档找到了一个数据库配置,现在可以使用了。这是配置:

'db' => array(
    'driver' => 'pdo',
    'username' => 'ourDbUsername',
    'password' => 'ourDbPassword',
    'dsn' => 'odbc:DRIVER={SQL Server Native Client 11.0};UID=ourDbUsername;PWD=ourDbPassword;DATABASE=ourDbName;SERVER=ourServerIP',
    'charset' => 'UTF-8'
),

到目前为止一切顺利。如果我们运行我们的应用程序,一切都会按预期进行,直到每次获取对象详细信息的简单 GET 请求都失败为止。即使我删除了在它之前执行的其他请求,我也无法使请求工作。即使以另一种方式链接请求也无济于事。这是错误:

Statement could not be executed (HY000 - 0 - [Microsoft][SQL Server Native Client 11.0]
Connection is busy with results for another command (SQLExecute[0] at /builddir/build/BUILD/php-5.4.16/ext/pdo_odbc/odbc_stmt.c:254) - HY000)

我们尝试设置 MARS_Connection(此处描述了 smozgur 的回答 How to fix native client error 'Connection is busy with results for another command'?)。但是我们没有这样的/etc/odbc.ini文件,只有/etc/odbcinst.ini文件。所以我们的/etc/odbcinst.ini 文件现在看起来像这样:

[ODBC Driver 11 for SQL Server]
Description=Microsoft ODBC Driver 11 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0
Threading=1
UsageCount=1
MARS_Connection=yes

我是否遗漏了我的设置中的某些内容以使其正常工作?

最佳答案

我试用了我的数据库连接,结果添加了“MARS_Connection=yes;”到我的 dsn 就可以了。

'db' => array(
    'driver' => 'pdo',
    'username' => 'ourDbUsername',
    'password' => 'ourDbPassword',
    'dsn' => 'odbc:DRIVER={SQL Server Native Client 11.0};UID=ourDbUsername;PWD=ourDbPassword;DATABASE=ourDbName;SERVER=ourServerIP;MARS_Connection=yes;',
    'charset' => 'UTF-8'
),

希望这可以帮助下一个搜索者!

关于php - 使用 Zend Framework 2 和 ODBC 驱动程序连接忙于 Linux 上的 MS SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35032821/

相关文章:

php - Zend HTTP 客户端密码

php - MySql 查询以检索 xml 的元素属性的值

mysql - 从 MS-SQL Server 查询转换为 MySQL 和 DATEDIFF()

c - C中的段错误

linux - bash 脚本仅在前面的代码完成后运行多个 C++ 代码

php - MySQL/PHP 自然排序

php - SELECT COUNT(*) 是否适用于 MySQLi 准备好的语句?

sql - SQL Server 出现不正确的语法错误

sql-server - 是否 CTE

linux - 以 root 用户身份运行 ElasticSearch