note 11968 added to class.pear.php
| From: | nospamm at pear dot net | Date: | Thu, 15 Mar 2001 18:23:48 +0000 |
| Subject: | note 11968 added to class.pear.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12439@lists.php.net to get a copy of this message | ||
Hi all!
We've coded a new functionallity for the fetchrow() (PEAR). This functionality is work as a
datasek.
Now, you can acess to a specific row of query's result. This is usefull for NEXT/PREV buttons
and more.
The codification now is only for MySQL. Could any people code the other databases?
The $row parameter is the value where you want to seek the internal pointer of the fetchrow result.
Default value is 0.
Modifications in DB.php:
Original function:
function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT) {
if ($fetchmode == DB_FETCHMODE_DEFAULT) {
$fetchmode = $this->dbh->fetchmode;
}
return $this->dbh->fetchRow($this->result, $fetchmode);
}
Modified function:
function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $row = 0) {
if ($fetchmode == DB_FETCHMODE_DEFAULT) {
$fetchmode = $this->dbh->fetchmode;
}
return $this->dbh->fetchRow($this->result, $fetchmode, $row);
}
Modifications in mysql.php:
Original function:
function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT) {
if ($fetchmode == DB_FETCHMODE_DEFAULT) {
$fetchmode = $this->fetchmode;
}
if ($fetchmode & DB_FETCHMODE_ASSOC) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
} else {
$row = mysql_fetch_row($result);
}
if (!$row) {
$errno = mysql_errno($this->connection);
if (!$errno) {
return NULL;
}
return $this->raiseError($this->errorCode($errno));
}
return $row;
}
Modificated function:
function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT,
$row = 0) {
if ($row > 0 && $row < (mysql_num_rows ($result)-1)) {
mysql_data_seek ($result, $row);
}
if ($fetchmode == DB_FETCHMODE_DEFAULT) {
$fetchmode = $this->fetchmode;
}
if ($fetchmode & DB_FETCHMODE_ASSOC) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
} else {
$row = mysql_fetch_row($result);
}
if (!$row) {
$errno = mysql_errno($this->connection);
if (!$errno) {
return NULL;
}
return $this->raiseError($this->errorCode($errno));
}
return $row;
}
Any feedback and improvements are welcome.
PiLoT & Jazze
http://www.php.net/manual/en/class.pear.php