home *** CD-ROM | disk | FTP | other *** search
- PostgreSQL Recordset
-
- PostgreSQL recordset class
-
- <?php
-
- //
- // Author: Razvan STANESCU <pappy@gecad.ro>
- //
-
- class CPGRs
- {
- var $recs;
- var $rows;
- var $cols;
-
- var $row;
-
- function CPGRs($pdb, $sql)
- {
- $this->recs = 0;
- $this->rows = 0;
- $this->cols = 0;
- $this->row = 0;
-
- $this->recs = pg_exec($pdb, $sql);
-
- if( $this->recs ) {
- $this->rows = pg_numrows($this->recs);
- $this->cols = pg_numfields($this->recs);
- $this->first();
- }
- return $this->recs && $this->rows > 0;
- }
-
- function valid()
- {
- return $this->recs;
- }
-
- function eof()
- {
- return $this->row == $this->rows;
- }
-
- function bof()
- {
- return $this->row < 0;
- }
-
- function first()
- {
- $this->row = 0;
- }
-
- function last()
- {
- $this->row = $this->rows-1;
- }
-
- function prev()
- {
- if( $this->row >= 0 ) {
- $this->row--;
- }
- }
-
- function next()
- {
- if( $this->row < $this->rows ) {
- $this->row++;
- }
- }
-
- function valueof($col)
- {
- if( $col < $this->cols ) {
- return pg_result($this->recs, $this->row, $col);
- }
- else {
- return "";
- }
- }
-
- function showheader($col, $fmt = "")
- {
- printf( "\t<th %s>%s</th>\n", $fmt, is_string($col) ? $col : pg_fieldname($this->recs, $col));
- }
-
- function showvalue($col, $fmt = "", $def = " ")
- {
- $v = $this->valueof($col);
- printf( "\t<td %s>%s</td>\n", $fmt, $v == "" ? $def : $v);
- }
-
- function showurl($col, $fmt = "")
- {
- $v = $this->valueof($col);
- if( $v != "" ) {
- printf( "\t<td %s> </td>\n", $fmt);
- }
- else {
- printf( "\t<td %s><a href=%s>%s</a></td>\n", $fmt, $v, $v);
- }
- }
-
- function display()
- {
- if( !$this->valid() ) {
- return;
- }
-
- printf( "<table cellspacing=1 cellpadding=1 border=1>\n");
-
- printf( "<tr>\n");
- for( $c = 0; $c < $this->cols; $c++ ) {
- $this->showheader($c);
- }
- printf( "</tr>\n");
-
- $this->first();
- while( !$this->eof() ) {
- printf( "<tr>\n");
-
- for( $c = 0; $c < $this->cols; $c++ ) {
- $this->showvalue($c);
- }
-
- printf( "</tr>\n");
- $this->next();
- }
- printf( "</table\n");
- }
-
- };
-
- ?>
-
-