ZF-4094: Row count column not found Error

Description

Getting this regression in v1.6.0RC3 in Zend_Paginator with the DbSelect adapter. Works fine with previous 1.6.0RC versions.

Fatal error: Uncaught exception 'Zend_Paginator_Exception' with message 'Row count column not found' in /var/www/ZendFramework-1.6.0RC3/library/Zend/Paginator/Adapter/DbSelect.php:102 Stack trace: #0 /var/www/ZendFramework-1.6.0RC3/library/Zend/Paginator/Adapter/DbSelect.php(175): Zend_Paginator_Adapter_DbSelect->setRowCount(Object(Zend_Db_Select)) #1 /var/www/ZendFramework-1.6.0RC3/library/Zend/Paginator.php(702): Zend_Paginator_Adapter_DbSelect->count() #2 /var/www/ZendFramework-1.6.0RC3/library/Zend/Paginator.php(476): Zend_Paginator->_calculatePageCount() #3 /var/www/html/working/stones/index.php(73): Zend_Paginator->setItemCountPerPage(20) #4 {main} thrown in /var/www/ZendFramework-1.6.0RC3/library/Zend/Paginator/Adapter/DbSelect.php on line 102

Sample code:


<?php
    require_once 'Zend/Paginator.php';
    require_once 'Zend/Db.php';

    try {
        $db = Zend_Db::factory('Mysqli', array(
            'host'     => 'localhost',
            'username' => 'name',
            'password' => 'pass',
            'dbname'   => 'message_stones',
        ));
        $db->getConnection();
    } catch (Zend_Db_Adapter_Exception $e) {
        die($e->getMessage());
    }

    $select = $db->select()->from('messages', array('id', 'name', 'message_line_1', 'wall', 'wall_row', 'wall_column'))->where("message_line_1 = ?", 'Smith');
    $paginator = Zend_Paginator::factory($select);
    $paginator->setItemCountPerPage(20);
    $paginator->setCurrentPageNumber(1);
    $view->paginator = $paginator;
?>

UPDATE: Okay, I had some time to debug it a bit. It looks like the fix for ZF-4001 broke it (revision 10942). Your your trying to cast an Zend_Db_Expr Object to a string which is a no go. Some dirty looking code there, I'm not sure how it works for anyone. This fixes it:


--- ZendFramework-1.6.1/library/Zend/Paginator/Adapter/DbSelect.php     2008-08-22 15:01:20.000000000 -0600
+++ ZendFramework-1.6.1-Fixed/library/Zend/Paginator/Adapter/DbSelect.php       2008-09-18 01:35:04.000000000 -0600
@@ -92,8 +92,8 @@
     {
         if ($rowCount instanceof Zend_Db_Select) {
             $columns = $rowCount->getPart(Zend_Db_Select::COLUMNS);
-
-            if (false === strpos((string) $columns[0][1], self::ROW_COUNT_COLUMN)) {
+
+            if (false === strpos($columns[0][1]->__toString(), self::ROW_COUNT_COLUMN)) {
                 /**
                  * @see Zend_Paginator_Exception
                  */

Ah, the problem is a pre PHP 5.2.0 bug as stated in the PHP docs: {quote} It is worth noting that before PHP 5.2.0 the __toString method was only called when it was directly combined with echo() or print(). {quote}

Comments

Could you provide some sample code?

I'm having this same issue. In RC2 I had to specify the from() in the select even if the select came from Zend_Db_Table, then in the final 1.6 release, it throws this exception.

I seem to be unable to reproduce this issue. Luke, could you perhaps provide some sample code as well?

Hmm... I must've overlooked the fact that it's a Zend_Db_Expr. Still, casting to a string should call __toString just the same. Anyway, thanks for this. I'll have a look at a fix in about an hour from posting this comment :)

Resolved in revision 11426