numRows implementation
| From: | Primax | Date: | Thu, 22 Mar 2001 17:31:34 +0000 |
| Subject: | numRows implementation | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-62@lists.php.net to get a copy of this message | ||
Hi people!
Here we go again, this time with the implementation of the numRows for
PEAR. We only coded the function for mySQL but it's really easy to
implement for the other databases but... we don't have many time :(
we hope you can do it for us ;)
Here is an example:
<?php
include ("conection.inc"); // Conection to your database
$sql= "SELECT * FROM table";
$nrows= $db->query($sql);
echo "Rows affected: ".$num = $result->numRows();
?>
DB.php
------
/**
* Get the the number of rows in a result set.
*
* @return int the number of columns, or a DB error code
*
* by Jose Maria Ramon Cardona (PiLoT) - SPAIN
* 03/22/2001
*/
function numRows() {
return $this->dbh->numRows($this->result);
}
mysql.php
--------
/**
* Get the number of columns in a result set.
*
* @param $result MySQL result identifier
*
* @access public
*
* @return int the number of columns per row in $result
*
* by Jose Maria Ramon Cardona (PiLoT) - SPAIN
* & Abel Almazán Fernández (Jazze) - SPAIN
* Date: 03/22/2001
*/
function numRows($result) {
$rows = mysql_num_rows($result);
if (!$rows) {
$errno = mysql_errno($this->connection);
if (!$errno) {
return NULL;
}
return $this->raiseError($this->errorCode($errno));
}
return $rows;
}
Any feedback and improvements are welcome.
PiLoT & Jazze
machines@teleline.es
abel.almazan@teleline.es