Zend 2.0 Select查询不起作用,但原始SQL中的相同查询有效

时间:2013-02-01 01:43:10

标签: php sql pdo zend-framework2

以下是我在Zend 2.0中创建查询的方法

$getVenues = $this->tableGateway->select(function (Select $select) {
    $select->where->greaterThanOrEqualTo('lat', (float) $lat_min);
    $select->where->greaterThanOrEqualTo('lng', (float) $lng_min);
    $select->where->lessThanOrEqualTo('lat', (float) $lat_max);
    $select->where->lessThanOrEqualTo('lng', (float) $lng_max);
});

正在输出以下查询:

SELECT `venues`.* FROM `venues` WHERE `lat` >= :where1 AND `lng` >= :where2 AND `lat` <= :where3 AND `lng` <= :where4

填写每个:where*的参数如下所示:

SELECT `venues`.* FROM `venues` WHERE `lat` >= 39.730387437667 AND `lng` >= -86.332592054637 AND `lat` <= 40.020242510131 AND `lng` <= -85.954901904578

在phpMyAdmin中执行原始SQL查询会返回正确的结果,但我的Zend 2.0查询返回0行。

以下是Zend的查询结果集var_dump

object(Zend\Db\ResultSet\ResultSet)#227 (8) {
  ["allowedReturnTypes":protected]=>
  array(2) {
    [0]=>
    string(11) "arrayobject"
    [1]=>
    string(5) "array"
  }
  ["arrayObjectPrototype":protected]=>
  object(Application\Model\Venue)#208 (12) {
    ["id"]=>NULL
    ["fsq_venue_id"]=>NULL
    ["name"]=>NULL
    ["address"]=>NULL
    ["city"]=>NULL
    ["state"]=>NULL
    ["zip"]=>NULL
    ["country"]=>NULL
    ["cross_street"]=>NULL
    ["lat"]=>NULL
    ["lng"]=>NULL
    ["updated_at"]=>NULL
  }
  ["returnType":protected]=>
  string(11) "arrayobject"
  ["buffer":protected]=>
  NULL
  ["count":protected]=>
  int(0)
  ["dataSource":protected]=>
  object(Zend\Db\Adapter\Driver\Pdo\Result)#214 (8) {
    ["statementMode":protected]=>
    string(7) "forward"
    ["resource":protected]=>
    object(PDOStatement)#215 (1) {
      ["queryString"]=>
      string(117) "SELECT `venues`.* FROM `venues` WHERE `lat` >= :where1 AND `lng` >= :where2 AND `lat` <= :where3 AND `lng` <= :where4"
    }
    ["options":protected]=>
    NULL
    ["currentComplete":protected]=>
    bool(false)
    ["currentData":protected]=>
    NULL
    ["position":protected]=>
    int(-1)
    ["generatedValue":protected]=>
    string(1) "0"
    ["rowCount":protected]=>
    int(0)
  }
  ["fieldCount":protected]=>
  int(12)
  ["position":protected]=>
  NULL
}

1 个答案:

答案 0 :(得分:0)

变量未在闭包上下文中设置