Re: numRows implementation
| From: | Primax | Date: | Thu, 22 Mar 2001 17:40:37 +0000 |
| Subject: | Re: numRows implementation | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-63@lists.php.net to get a copy of this message | ||
Ups... There was a bug in my example
The correct one is:
<?php
include ("conection.inc"); // Conection to your database
$sql= "SELECT * FROM table";
$nrows= $db->query($sql);
echo "Rows affected: ". $nrows->numRows();
?>
PiLoT
> 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
>
> --
> PEAR Development Mailing List (http://pear.php.net/)
> To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: pear-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net