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.

  • 写回答

1条回答 默认 最新

  • duanke1984 2018-05-15 08:52
    关注

    The issue here is that ZF2 is not compatible with PHP > 5.6. In this instance the API for sqlsrv has been made stricter due to deprecation of "call-time pass-by-reference". The solution is to stick with PHP 5.6 or refactor a large amount of the code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图