+ Reply to Thread
Results 1 to 3 of 3

Thread: i want count rows

  1. #1
    neworld is offline Junior Member
    Join Date
    Feb 2008
    Posts
    2

    Default i want count rows

    I show my code:

    [PHP]class users extends Zend_Db_Table_Abstract
    {
    protected $_name = 'users';

    public function select() {
    return $this->getAdapter()->select();
    }

    public function countusers() {
    $select = $this->select();
    $select->from($this->_name,'COUNT(id) AS num');
    $row=$this->fetchRow($select);
    return $row->num;
    }
    } [/PHP]

    but then, i want countusers, I get:

    Code:
    Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10' in /home/banners/domains/vipuff.com/public_html/library/Zend/Db/Statement/Pdo.php:227 Stack trace: #0 /home/banners/domains/vipuff.com/public_html/library/Zend/Db/Statement.php(279): Zend_Db_Statement_Pdo->_execute(Array) #1 /home/banners/domains/vipuff.com/public_html/library/Zend/Db/Adapter/Abstract.php(396): Zend_Db_Statement->execute(Array) #2 /home/banners/domains/vipuff.com/public_html/library/Zend/Db/Adapter/Pdo/Abstract.php(206): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Select), Array) #3 /home/banners/domains/vipuff.com/public_html/library/Zend/Db/Table/Abstract.php(1104): Zend_Db_Adapter_Pdo_Abstract->query(Object(Zend_Db_Select)) #4 /home/banners/domains/vipuff.com/public_html/library/Zend/Db/Table/Abstract.php(1011): Zend_Db_Tab in /***/***/public_html/library/Zend/Db/Statement/Pdo.php on line 227
    if i write echo $select in true place, and see query, who work in phpmyadmint, but no work in users->countusers();.

    Any ideas?

  2. #2
    Salz` is offline Junior Member
    Join Date
    Feb 2008
    Posts
    3

    Default

    try
    Code:
        public function countusers() {
            $select = $this->select();
            $select->from($this->_name,'COUNT(*) AS num');
            return $this->fetchRow($select)->num;
        }
    edit: oh, and you should have a look at How can I get the number of rows in a query?

  3. #3
    neworld is offline Junior Member
    Join Date
    Feb 2008
    Posts
    2

    Default

    I update prototype to 1.5.0 PR and my code work.

+ Reply to Thread

Similar Threads

  1. Problem with Count in Zend_Form
    By robos85 in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 02-11-2010, 01:14 PM
  2. Zend count query
    By ganesh in forum General Q&A on Zend Framework
    Replies: 1
    Last Post: 05-22-2009, 01:45 PM
  3. get page count in pdf
    By vasu in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 10-16-2008, 06:32 AM
  4. php count() or sql count(*) is faster??
    By iroy2000 in forum General Talks
    Replies: 5
    Last Post: 04-17-2008, 07:27 PM
  5. Newbie question on count
    By Michel in forum Databases
    Replies: 7
    Last Post: 04-14-2008, 02:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts