Database_Result Class Reference

Inherited by DB_Mysql_Result.

List of all members.

Public Member Functions

  • __construct ($resResult, $strQuery)
    Validate the connection resource and store the query.
  • __destruct ()
    Automatically free the current result.
  • __set ($strKey, $strValue)
    Set a particular field of the current row.
  • __get ($strKey)
    Return a result parameter or a particular field of the current row.
  • fetchRow ()
    Fetch the current row as enumerated array.
  • fetchAssoc ()
    Fetch the current row as associative array.
  • fetchEach ($strKey)
    Fetch a particular field of each row of the result.
  • fetchAllAssoc ()
    Fetch all rows as associative array.
  • fetchField ($intOffset=0)
    Get column information and return it as array.
  • first ()
    Go to the first row of the current result.
  • next ()
    Go to the next row of the current result.
  • prev ()
    Go to the previous row of the current result.
  • last ()
    Go to the last row of the current result.
  • row ($blnFetchArray=false)
    Return the current row as associative array.
  • reset ()
    Reset the current result.

Protected Member Functions

Protected Attributes

Private Attributes


Detailed Description

Definition at line 684 of file Database.php.


Constructor & Destructor Documentation

Database_Result::__construct ( resResult,
strQuery 
)

Validate the connection resource and store the query.

Parameters:
resource 
string 
Exceptions:
Exception 

Definition at line 736 of file Database.php.

00737         {
00738                 if (!is_resource($resResult) && !is_object($resResult))
00739                 {
00740                         throw new Exception('Invalid result resource');
00741                 }
00742 
00743                 $this->resResult = $resResult;
00744                 $this->strQuery = $strQuery;
00745         }

Database_Result::__destruct (  ) 

Automatically free the current result.

Definition at line 751 of file Database.php.

00752         {
00753                 $this->free();
00754         }


Member Function Documentation

Database_Result::__get ( strKey  ) 

Return a result parameter or a particular field of the current row.

Supported parameters:

  • query: corresponding query string
  • numRows: number of rows of the current result
  • numFields: fields of the current result

Throw an exception on requests for unknown fields.

Parameters:
string 
Returns:
string

Definition at line 786 of file Database.php.

00787         {
00788                 switch ($strKey)
00789                 {
00790                         case 'query':
00791                                 return $this->strQuery;
00792                                 break;
00793 
00794                         case 'NumRows':
00795                         case 'numRows':
00796                                 return $this->num_rows();
00797                                 break;
00798 
00799                         case 'numFields':
00800                                 return $this->num_fields();
00801                                 break;
00802 
00803                         case 'isModified':
00804                                 return $this->blnModified;
00805                                 break;
00806 
00807                         default:
00808                                 if ($this->intIndex < 0)
00809                                 {
00810                                         $this->first();
00811                                 }
00812                                 if (isset($this->arrCache[$this->intIndex][$strKey]))
00813                                 {
00814                                         return $this->arrCache[$this->intIndex][$strKey];
00815                                 }
00816                                 return null;
00817                                 break;
00818                 }
00819         }

Database_Result::__set ( strKey,
strValue 
)

Set a particular field of the current row.

Parameters:
string 
string 

Definition at line 762 of file Database.php.

00763         {
00764                 if ($this->intIndex < 0)
00765                 {
00766                         $this->first();
00767                 }
00768 
00769                 $this->blnModified = true;
00770                 $this->arrCache[$this->intIndex][$strKey] = $strValue;
00771         }

Database_Result::fetch_assoc (  )  [abstract, protected]

Reimplemented in DB_Mysql_Result.

Referenced by fetchAssoc().

Database_Result::fetch_field ( intOffset  )  [abstract, protected]

Reimplemented in DB_Mysql_Result.

Referenced by fetchField().

Database_Result::fetch_row (  )  [abstract, protected]

Abstract database driver methods.

Reimplemented in DB_Mysql_Result.

Referenced by fetchRow().

Database_Result::fetchAllAssoc (  ) 

Fetch all rows as associative array.

Returns:
array

Definition at line 891 of file Database.php.

Referenced by fetchEach(), and last().

00892         {
00893                 do
00894                 {
00895                         $blnHasNext = $this->fetchAssoc();
00896                 }
00897                 while ($blnHasNext);
00898 
00899                 return $this->arrCache;
00900         }

Database_Result::fetchAssoc (  ) 

Fetch the current row as associative array.

Returns:
array

Definition at line 847 of file Database.php.

Referenced by fetchAllAssoc(), first(), and next().

00848         {
00849                 if (!isset($this->arrCache[++$this->intIndex]))
00850                 {
00851                         if (($arrRow = $this->fetch_assoc()) == false)
00852                         {
00853                                 --$this->intIndex;
00854                                 return false;
00855                         }
00856 
00857                         $this->arrCache[$this->intIndex] = $arrRow;
00858                 }
00859 
00860                 return $this->arrCache[$this->intIndex];
00861         }

Database_Result::fetchEach ( strKey  ) 

Fetch a particular field of each row of the result.

Parameters:
string 
Returns:
array

Definition at line 869 of file Database.php.

00870         {
00871                 $arrReturn = array();
00872 
00873                 if ($this->intIndex < 0)
00874                 {
00875                         $this->fetchAllAssoc();
00876                 }
00877 
00878                 foreach ($this->arrCache as $arrRow)
00879                 {
00880                         $arrReturn[] = $arrRow[$strKey];
00881                 }
00882 
00883                 return $arrReturn;
00884         }

Database_Result::fetchField ( intOffset = 0  ) 

Get column information and return it as array.

Parameters:
int 
Returns:
array

Definition at line 908 of file Database.php.

00909         {
00910                 $arrFields = $this->fetch_field($intOffset);
00911 
00912                 if (is_object($arrFields))
00913                 {
00914                         $arrFields = get_object_vars($arrFields);
00915                 }
00916 
00917                 return $arrFields;
00918         }

Database_Result::fetchRow (  ) 

Fetch the current row as enumerated array.

Returns:
array

Definition at line 826 of file Database.php.

00827         {
00828                 if (!$this->arrCache[++$this->intIndex])
00829                 {
00830                         if (($arrRow = $this->fetch_row()) == false)
00831                         {
00832                                 --$this->intIndex;
00833                                 return false;
00834                         }
00835 
00836                         $this->arrCache[$this->intIndex] = $arrRow;
00837                 }
00838 
00839                 return array_values($this->arrCache[$this->intIndex]);
00840         }

Database_Result::first (  ) 

Go to the first row of the current result.

Returns:
object

Definition at line 925 of file Database.php.

Referenced by __get(), __set(), and row().

00926         {
00927                 if (!$this->arrCache)
00928                 {
00929                         $this->arrCache[++$this->intRowIndex] = $this->fetchAssoc();
00930                 }
00931 
00932                 $this->intIndex = 0;
00933                 return $this;
00934         }

Database_Result::last (  ) 

Go to the last row of the current result.

Returns:
mixed

Definition at line 988 of file Database.php.

00989         {
00990                 if (!$this->blnDone)
00991                 {
00992                         $this->arrCache = $this->fetchAllAssoc();
00993                 }
00994 
00995                 $this->blnDone = true;
00996                 $this->intIndex = $this->intRowIndex = count($this->arrCache) - 1;
00997 
00998                 return $this;
00999         }

Database_Result::next (  ) 

Go to the next row of the current result.

Returns:
mixed

Definition at line 941 of file Database.php.

00942         {
00943                 if ($this->blnDone)
00944                 {
00945                         return false;
00946                 }
00947 
00948                 if (!isset($this->arrCache[++$this->intIndex]))
00949                 {
00950                         if (($arrRow = $this->fetchAssoc()) == false)
00951                         {
00952                                 $this->blnDone = true;
00953                                 --$this->intIndex;
00954 
00955                                 return false;
00956                         }
00957 
00958                         $this->arrCache[$this->intIndex] = $arrRow;
00959                         ++$this->intRowIndex;
00960 
00961                         return $this;
00962                 }
00963 
00964                 return $this;
00965         }

Database_Result::num_fields (  )  [abstract, protected]

Reimplemented in DB_Mysql_Result.

Referenced by __get().

Database_Result::num_rows (  )  [abstract, protected]

Reimplemented in DB_Mysql_Result.

Referenced by __get().

Database_Result::prev (  ) 

Go to the previous row of the current result.

Returns:
mixed

Definition at line 972 of file Database.php.

00973         {
00974                 if ($this->intIndex == 0)
00975                 {
00976                         return false;
00977                 }
00978 
00979                 --$this->intIndex;
00980                 return $this;
00981         }

Database_Result::reset (  ) 

Reset the current result.

Returns:
object

Definition at line 1022 of file Database.php.

01023         {
01024                 $this->intIndex = -1;
01025                 $this->blnDone = false;
01026 
01027                 return $this;
01028         }

Database_Result::row ( blnFetchArray = false  ) 

Return the current row as associative array.

Parameters:
boolean 
Returns:
array

Definition at line 1007 of file Database.php.

01008         {
01009                 if ($this->intIndex < 0)
01010                 {
01011                         $this->first();
01012                 }
01013 
01014                 return $blnFetchArray ? array_values($this->arrCache[$this->intIndex]) : $this->arrCache[$this->intIndex];
01015         }


Member Data Documentation

Database_Result::$arrCache = array() [protected]

Definition at line 727 of file Database.php.

Database_Result::$blnDone = false [private]

Definition at line 715 of file Database.php.

Database_Result::$blnModified = false [private]

Definition at line 721 of file Database.php.

Database_Result::$intIndex = -1 [private]

Definition at line 703 of file Database.php.

Database_Result::$intRowIndex = -1 [private]

Definition at line 709 of file Database.php.

Database_Result::$resResult [protected]

Definition at line 691 of file Database.php.

Referenced by __construct().

Database_Result::$strQuery [protected]

Definition at line 697 of file Database.php.

Referenced by __construct().


The documentation for this class was generated from the following file: