Zend Framework 2.2.4的限制条款中是否存在错误

时间:2013-09-18 22:04:44

标签: php zend-framework zend-framework2

$db_adapter = new Zend\Db\Adapter\Adapter(array(
'driver' => 'pdo_mysql',
'database' => 'xxxx',
'username' => 'xxxx',
'password' => 'xxxx',
'hostname' => 'xxxx'
    ));

$select1 = new Zend\Db\Sql\select();
$select1-> from('states');
$select1-> columns(array('name', 'id'));
$select1-> where ->notEqualTo('name', 'Florida');
$select1-> limit(5);

echo "<br />Query: ". $select1-> getSqlString() . '<br />';
$adaptor    = new Zend\Paginator\Adapter\DbSelect($select1, $db_adapter);
echo "<br />Row count: ". $adaptor->count();

问题在于:我有一个名为states的表,其中有73条记录。当我运行上面的脚本时,我一直得到73条记录,似乎 LIMIT子句根本没有生效。除非限制条款根本不起作用,否则我不确定我做错了什么。这是输出:     

    Query: SELECT "jb_states"."name" AS "name", 
    "jb_states"."id" AS "id" FROM "jb_states" 
    WHERE "name" != 'Florida' LIMIT '5'
    Row count: 73 
    

Zend Framework 2.2.4版,数据库:mysql

1 个答案:

答案 0 :(得分:3)

$adaptor->count()旨在返回结果集中行数。它会在运行查询之前删除任何限制子句,以便解决此问题。