Ver Mensaje Individual
  #36 (permalink)  
Antiguo 13/08/2007, 17:10
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 20 años, 4 meses
Puntos: 2135
Re: Pregunta de principiante...

2da parte:
Código PHP:
<?php
/**
 * GeckoDBResult
 * 
 * @package com.geckowd.utils;
 * @author Christopher Valderrama <[email protected]>
 * @copyright Copyright (c) 2005
 * @version $Id$1.0$26 Oct 2005
 * @access private
 **/
class GeckoDBResult {
    var 
$_result; // @var resource the resultset of the current MySQL result
    
var $_query; // @var string the current query sent
    
var $rows; // @var integer the number of rows (read only)
    
    /**
     * GeckoDBResult::GeckoDBResult()
     * 
     * Constructor, returns a new instance of GeckoDBResult
     * 
     * @param string $query
     * @param resource $result
     * @return GeckoDBResult a new instance of the class
     **/
    
function GeckoDBResult( $query, $result ) {
        
$this->_result     = $result;
        
$this->_query     = $query;
        
        
$this->rows = mysql_num_rows( $this->_result );
    }
    
    
/**
     * GeckoDBResult::getQuery()
     * 
     * This function will return the query of this class
     * 
     * @access public
     * @return string the query of this class
     **/
    
function getQuery() {
        return 
$this->_query;
    }
    
    
/**
     * GeckoDBResult::numRows()
     * 
     * This function will return the total number of records for this resultset
     * 
     * @access public
     * @return integer the number of rows for this resultset
     **/
    
function numRows() {
        return 
$this->rows;
    }

    
/**
     * GeckoDBResult::numFields()
     * 
     * This function return the number of fields for the current query
     * 
     * @access public
     * @return integer the number of fields
     **/
    
function numFields() {
        return 
mysql_num_fields( $this->_result );
    }
    
    
/**
     * GeckoDBResult::fetchField()
     * 
     * This function will return the name of the field specified by $fieldNumber
     * 
     * @access public
     * @param integer $fieldNumber
     * @return string the name of the field
     **/
    
function fetchField( $fieldNumber ) {
        return 
mysql_field_name( $this->_result, $fieldNumber );
    }

    
/**
     * GeckoDBResult::fetchRow()
     * 
     * This function will return the current row of the query or false when no more rows are left
     * 
     * @access public
     * @param integer $fetchMode
     * @param boolean $stripResult
     * @return mixed the current result of the active row or false when no more records are found
     **/
    
function fetchRow( $fetchMode = MYSQL_BOTH, $stripResult = true ) {
        
$row = mysql_fetch_array( $this->_result, $fetchMode );
        if( 
is_array( $row ) && ( $stripResult ) ) {
            
$row = array_map( "stripslashes", $row );
        }
        
        return 
$row;
    }
    
    
/**
     * GeckoDBResult::fetchAll()
     * 
     * This function will fetch ALL rows of a resultset and return a array with each element of the array
     * equal to a row of the result
     * 
     * @access public
     * @param integer $fetchMode
     * @param boolean $stripResult
     * @return mixed the current result of the active row or false when no more records are found
     **/
    
function fetchAll( $fetchMode = MYSQL_BOTH, $stripResult = true ) {
        
$rows = array();
        
        while( 
$row = $this->fetchRow( $fetchMode, $stripResult ) ) $rows[] = $row;
        
        return 
$rows;
    }
    
    
/**
     * GeckoDBResult::fetchColumn()
     * 
     * This function will fetch the first value of the query, but will itirate all of the values to make a column or list
     * 
     * @access public
     * @param integer $fetchMode
     * @param boolean $stripResult
     * @return mixed the current result of the active row or false when no more records are found
     **/
    
function fetchColumn() {
        
$column = array();
        
        while( 
$value = $this->fetchFirst() ) $column[] = $value;
        
        return 
$column;
    }
    
    
/**
     * GeckoDBResult::fetchFirst()
     * 
     * This function will return the first value of a query
     * 
     * @access public
     * @return mixed The value of the query or false on no rows
     **/
    
function fetchFirst() {
        
$result = false;
        
$row = $this->fetchRow( MYSQL_NUM, true );
        if( 
is_array( $row ) ) {
            
$result = $row[0];
        }
        
        return 
$result;
    }
    
    
/**
     * GeckoDBResult::seekRow()
     * 
     * This function will seek to a specified result in the active resultset
     * 
     * @access public
     * @param integer $rowNumber
     * @return boolean will attemp to seek to a result on the active resultset
     **/
    
function seekRow( $rowNumber ) {
        return @
mysql_data_seek( $this->_result, $rowNumber );
    }

    
/**
     * GeckoDBResult::fetchLastRow()
     * 
     * This function will return the last row on the active resultset
     * 
     * @access public
     * @param integer $fetchMode
     * @param boolean $stripResult
     * @return array the last result of the active resultset
     **/
    
function fetchLastRow( $fetchMode = MYSQL_BOTH, $stripResult = true ) {
        
$this->seekRow( $this->numRows() - 1 );
        return 
$this->fetchRow( $fetchMode, $stripResult );
    }
    
    
/**
     * GeckoDBResult::clearResult()
     * 
     * This function will clear the current resultset
     * 
     * @return boolean if the result could be cleared
     **/
    
function clearResult() {
        if( 
is_resource( $this->_result ) ) {
            return @
mysql_free_result( $this->_result );
        }
    }
    function 
delete() {
        return 
$this->clearResult();
    }
}
?>
Le quite un poco de documentación porque esta muy larga y no me dejaba publicarla jeje

Saludos.