douya1061
2018-05-11 10:05
浏览 85
已采纳

ZF2 TableGateway查询返回空结果集,适配器查询工作正常

I've moved an application between servers.

From:

  • Windows 2008 R2
  • ISS 6.1
  • PHP 5.4.11
  • SQL Server 10
  • ZF 2.4

To:

  • Windows 10
  • PHP built-in server
  • PHP 7.2.5
  • SQL Server 14
  • ZF 2.4

Below the TableGateway selectWith() returns an empty resultset but when the same $select is queried via Adapter->query() it works as expected. It worked fine on the previous server. The TableGateway selectWith() is the original code and needs to work. Apart from the version numbers above, nothing else has changed.

    $select = $this->tableGateway->getSql()->select()->where(array(
        'col1 = ?' => $input
    ));

    // via selectWith
    $resultSet = $this->tableGateway->selectWith($select);

    // via query
    $selectString = $this->tableGateway->getSql()->buildSqlString($select);
    $adapter = $this->tableGateway->getAdapter();
    $results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);

    // works
    var_dump($results->current());
    // doesn't work
    var_dump($resultSet->current());

Update:

$select = $this->tableGateway->getSql()->select()->where(array(
   'col1 = \''.$input.'\''
));

The above code works. So the problem must be with the way TableGateway Select placeholder and replacements. I've tried all the variations in the docs and they should work but don't.

Further update:

Obviously one of these uses sqlsrv_query and the other uses sqlsrv_execute. I've been through the library and there must be a problem with the way it binds params to sqlsrv_prepare but I haven't got to the bottom of it yet. sqlsrv_prepare requires pass by reference. I suspect the bug is an incompability with this breaking change between 5.6 and 7.

图片转代码服务由CSDN问答提供 功能建议

我在服务器之间移动了一个应用程序。

来自 :

  • Windows 2008 R2
  • ISS 6.1
  • PHP 5.4.11
  • SQL Server 10
  • ZF 2.4

    收件人:

    • Windows 10
    • PHP内置服务器
    • PHP 7.2.5
    • SQL Server 14
    • ZF 2.4

      TableGateway selectWith()返回一个空结果集但是当通过 Adapter-> query()查询相同的 $ select 时,它按预期工作。 它在以前的服务器上工作正常。 TableGateway selectWith()是原始代码,需要工作。 除了上面的版本号,没有其他任何改变。

        $ select = $ this-> tableGateway-> getSql(  ) - > select() - > where(array(
      'col1 =?'=> $ input 
      )); 
       
       // via selectWith 
       $ resultSet = $ this-> tableGateway  - > selectWith($ select); 
       
       //通过查询
       $ selectString = $ this-> tableGateway-> getSql() - > buildSqlString($ select); 
       $ adapter = $ this  - > tableGateway-> getAdapter(); 
       $ results = $ adapter-> query($ selectString,$ adapter :: QUERY_MODE_EXECUTE); 
       
       // works 
       var_dump($ results-> current  ()); 
       //不起作用
       var_dump($ resultSet-> current()); 
         
       
       

      更新:

        $ select = $ this-> tableGateway-> getSql() - > select() - > where(array(
      'col1 = \  ''。$ input。'\''
      )); 
         
       
       

      以上代码有效。 所以问题必须与TableGateway Select占位符和替换方式一致。 我已经尝试了文档中的所有变体,但它们应该可以工作但不能。

      进一步更新:

      显然,其中一个使用 sqlsrv_query ,另一个使用 sqlsrv_execute 。 我已经浏览了库,并且它将params绑定到 sqlsrv_prepare 的方式一定存在问题,但我还没有到底。 sqlsrv_prepare 需要按引用传递。 我怀疑这个错误在5.6和7之间的这种突破性变化是不合适的。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题