winteck
winteck

Reputation: 417

Is there a bug in the Limit Clause for Zend Framework 2.2.4

$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();

Here is the problem: I have a table called states that has 73 records in it. When i run the script above i keep getting 73 records, it does seem that the LIMIT clause does not take effect at all. I am not sure what i am doing wrong unless the limit clause is simply not working. here is the output:

    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 version 2.2.4, database:mysql

Upvotes: 0

Views: 310

Answers (1)

Tim Fountain
Tim Fountain

Reputation: 33148

$adaptor->count() is designed to return the total number of rows in the result set. It removes any limit clause before running the query in order to work this out.

Upvotes: 3

Related Questions