PEAR fetchRow() modification

From: Date: Fri, 16 Mar 2001 09:46:37 +0000
Subject: PEAR fetchRow() modification
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-28@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 results row number that you want to retrieve Default value is 0. Calling function example: We need the 4th row of the query result (rows start at 0): $row = $result->fetchRow(DB_FETCHMODE_ASSOC,3) 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

« previous php.pear.dev (#28) next »