Source for file jDbPDOResultSet.class.php

Documentation is available at jDbPDOResultSet.class.php

  1. <?php
  2. /**
  3. * @package    jelix
  4. * @subpackage db
  5. * @author     Laurent Jouanneau
  6. * @contributor Gwendal Jouannic, Thomas, Julien Issler
  7. * @copyright  2005-2010 Laurent Jouanneau
  8. * @copyright  2008 Gwendal Jouannic, 2009 Thomas
  9. * @copyright  2009 Julien Issler
  10. * @link      http://www.jelix.org
  11. * @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  12. */
  13.  
  14. /**
  15.  * a resultset based on PDOStatement
  16.  * @package  jelix
  17.  * @subpackage db
  18.  */
  19. class jDbPDOResultSet extends PDOStatement {
  20.  
  21.     const FETCH_CLASS = 8;
  22.  
  23.     protected $_fetchMode = 0;
  24.  
  25.     public function fetch ($fetch_style = PDO::FETCH_BOTH, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0) {
  26.         $rec = parent::fetch();
  27.         if ($rec && count($this->modifier)) {
  28.             foreach($this->modifier as $m)
  29.                 call_user_func_array($m, array($rec, $this));
  30.         }
  31.         return $rec;
  32.     }
  33.  
  34.     /**
  35.      * return all results from the statement.
  36.      * Arguments are ignored. JDb don't care about it (fetch always as classes or objects)
  37.      * But there are here because of the compatibility of internal methods of PDOStatement
  38.      * @param integer $fetch_style ignored
  39.      * @param integer $column_index 
  40.      * @param array $ctor_arg  (ignored)
  41.      * @return array list of object which contain all rows
  42.      */
  43.     public function fetchAll ($fetch_style = PDO::FETCH_OBJ, $column_index=0, $ctor_arg=null) {
  44.         if ($this->_fetchMode) {
  45.             if ($this->_fetchMode != PDO::FETCH_COLUMN)
  46.                 return parent::fetchAll($this->_fetchMode);
  47.             else
  48.                 return parent::fetchAll($this->_fetchMode, $column_index);
  49.         }
  50.         else {
  51.             return parent::fetchAll(PDO::FETCH_OBJ);
  52.         }
  53.     }
  54.  
  55.     /**
  56.      * Set the fetch mode.
  57.      * @param int $mode  the mode, a PDO::FETCH_* constant
  58.      * @param mixed $arg1 a parameter for the given mode
  59.      * @param mixed $arg2 a parameter for the given mode
  60.      */
  61.     public function setFetchMode($mode, $arg1=null , $arg2=null){
  62.         $this->_fetchMode = $mode;
  63.         // depending the mode, original setFetchMode throw an error if wrong arguments
  64.         // are given, even if there are null
  65.         if ($arg1 === null)
  66.             return parent::setFetchMode($mode);
  67.         else if ($arg2 === null)
  68.             return parent::setFetchMode($mode, $arg1);
  69.         return parent::setFetchMode($mode, $arg1, $arg2);
  70.     }
  71.  
  72.     /**
  73.      * @param string $text a binary string to unescape
  74.      * @since 1.1.6
  75.      */
  76.     public function unescapeBin($text) {
  77.         return $text;
  78.     }
  79.  
  80.     /**
  81.      * a callback function which will modify on the fly record's value
  82.      * @var array of callback
  83.      * @since 1.1.6
  84.      */
  85.     protected $modifier = array();
  86.  
  87.     /**
  88.      * @param callback $function a callback function
  89.      *      the function should accept in parameter the record,
  90.      *      and the resulset object
  91.      * @since 1.1.6
  92.      */
  93.     public function addModifier($function) {
  94.         $this->modifier[] = $function;
  95.     }
  96. }

Documentation generated on Mon, 19 Sep 2011 14:12:29 +0200 by phpDocumentor 1.4.3