Page 1 of 1

Quick Zend_DB Question

Posted: Mon Sep 17, 2007 10:46 am
by seodevhead
Two Questions rather...

1) I currently have MySQL 4.1 installed and use the mysql extension (NOT mysqli). I don't want to upgrade to mysqli use and just want to keep using the mysql php extension. But I want to start using the Zend_Db class and notice they offer two ways of connecting to MySQL... PDO and a MySQLi adapter. I can use the PDO method with my current setup (mysql extension), right? My current scripts that don't use PDO but use the mysql extension will still work when I setup my server to work with the Zend_DB (PDO) class, right?

2) Lastly... Just reading through the Zend_Db reference manual... everything looks really good... but I'm not quite sure what replaces the mysql_num_rows() function when using Zend_Db. Example:

Code: Select all

$sql = 'SELECT * FROM bugs WHERE bug_id = ?';

$result = $db->fetchAll($sql, 2);
How would I go about counting the number of rows returned? Would it be:

Code: Select all

$rowsReturned = count($result);
Thanks for your advice.

Posted: Mon Sep 17, 2007 2:50 pm
by Begby
You need to have your system setup to use PDO. This varies on the version of PHP you use. IMO PDO is much better anyways. You can still use the regular mysql function and PDO, however I don't think you can share the connection. That means your script will have two connections open to the db.

If you use fetchAll() it returns an array, so yes, you can use count() to get the number of records.