SQL databases do not report the number of rows that are expected to be
returned by a query. The information is simply not available until
after the client has fetched the rows.
All client libraries that offer a method numRows() (or a method with
similar functionality) work by first fetching all the rows until the
result set is complete, and then doing a count() on the resulting array
of rows. For example read this text from:
http://dev.mysql.com/doc/refman/5.0/en/mysql-num-rows.html
"The use of mysql_num_rows() depends on whether you use
mysql_store_result() or mysql_use_result() to return the result set. If
you use mysql_store_result(), mysql_num_rows() may be called
immediately. If you use mysql_use_result(), mysql_num_rows() does not
return the correct value until all the rows in the result set have been
retrieved."
So you can do this in Zend Framework in the following way:
$result = $db->fetchAll( $select );
echo count($result);
Regards,
Bill Karwin
________________________________
From: Shawn McAllister [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 28, 2007 12:51 PM
To: [email protected]
Subject: RE: [fw-general] numRows method missing in db adapter
ok... well the docs need to reflect this... currently they say
"Returns the number of rows affected by the execution of the last
INSERT, DELETE, or UPDATE statement executed by this statement object."
Shawn McAllister
________________________________
From: Arthur M. Kang [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 28, 2007 3:44 PM
To: Shawn McAllister
Cc: [email protected]
Subject: Re: [fw-general] numRows method missing in db adapter
You can use $stmt->rowCount().
Arthur
Shawn McAllister wrote:
I am using the MySqli adapter for our xmlrpc data api.
We recently decided to use the Zend_Db classes just to maintain
consistency... before we were using our own custom MySqli adapter class
that we wrote to support slave database servers and so on... well as I
am porting the code to Zend_Db I noticed that there is my method to
return a count of rows from a query... what's up with that? Am I just
missing something or being we todd did?
Shawn McAllister