php - 选择 Doctrine 和 MS SQL 2008 的问题

标签 php sql-server sql-server-2008 doctrine-orm freetds

我们已经使用 Doctrine2 编写了一个应用程序,它在与 MySQL 或 Postgres 数据库一起使用时效果很好。

我们现在使用 PDO Driver DBLib 将应用程序连接到 SQL Server 2008 数据库它使用 SQL Server 和 Sybase 共享的 TDS(表格数据流协议(protocol))的 FreeTDS 实现。

在对 Doctrine SQLServerPlatform 和我们的 MSSQL 驱动程序包进行一些调整之后,初始模式创建、事务和 INSERT 到表中工作正常。

但是在选择数据的时候,我们会遇到如下错误:

General error: 20019 Attempt to initiate a new Adaptive Server operation with results pending

经过大量谷歌搜索后,我找到了 this detail in the FAQ of FreeTDS :

If you are accustomed to programming with other database servers, you may be surprised when you first encounter this aspect of the TDS protocol. [...]

The server requires the client either to read all the results from a query, or to indicate that no further rows are desired i.e., to issue a cancellation. Until one of those two things happens, the server will not accept new queries on that connection. It will complain about "pending results".

所以出现错误信息的原因是因为某些原因,Doctrine (DBAL->PDO->FreeTDS) 没有从连接缓冲区中读取所有的结果行,服务器/库不允许应用程序发出新的 exec()/execute() 直到读取所有行。

  • 我的理解是否正确,$doctrinequery->getResults() 在返回之前获取所有结果?
  • 我的理解是否正确,$entity->getLinkedEntity()(即 $user->getGroupNames())在返回之前获取所有结果?
  • 您将如何解决问题的确切位置?
    堆栈跟踪对我们没有任何帮助,代码库已经增长。
  • 是否还有其他人遇到过这个问题并可以分享一些见解?
  • 有没有我们可以用来将 Doctrine 连接到 MSSQL 而不会遇到这个问题的替代方法?

最佳答案

我在 PDO 驱动程序 DBLib 和事务方面遇到了类似的问题。我是这样修复的:

$this->_db->beginTransaction();

$st = $this->_db->prepare("StoredProcedure ?");
$st->execute(array($data));
$results= $st->fetchAll();
$st->closeCursor();

// more stuff

$this->_db->commit();

closeCursor() 解决了我的问题:http://php.net/manual/en/pdostatement.closecursor.php

关于php - 选择 Doctrine 和 MS SQL 2008 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13280717/

相关文章:

php - Mysql-php mysql_fetch_array()

php - 当我在 PHP 中使用 cURL 发布文件时,我应该设置 CURLOPT_UPLOAD 吗?

sql - 计算一段时间后或基于辅助列的重复出现次数

xml - sql server 2008 xml文件到表

c# - 我可以将 DBNull 传递给 Integer 类型变量吗?

sql - 想要透视表。并生成动态 SQL 字符串并执行

php - Symfony3 404 NotFoundHttpException

php - 通过html的提交按钮上传文件而不是flash的上传按钮

sql - 如何根据给定参数执行查询

sql - 仅当列值为 true 时才连接到表