Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/dml/pdo_moodle_recordset.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 require_once($CFG->libdir.'/dml/moodle_recordset.php');
00031 
00035 class pdo_moodle_recordset extends moodle_recordset {
00036 
00037     private $sth;
00038     protected $current;
00039 
00040     public function __construct($sth) {
00041         $this->sth = $sth;
00042         $this->sth->setFetchMode(PDO::FETCH_ASSOC);
00043         $this->current = $this->fetch_next();
00044     }
00045 
00046     public function __destruct() {
00047         $this->close();
00048     }
00049 
00050     private function fetch_next() {
00051         if ($row = $this->sth->fetch()) {
00052             $row = array_change_key_case($row, CASE_LOWER);
00053         }
00054         return $row;
00055     }
00056 
00057     public function current() {
00058         return (object)$this->current;
00059     }
00060 
00061     public function key() {
00063         if (!$this->current) {
00064             return false;
00065         }
00066         $key = reset($this->current);
00067         return $key;
00068     }
00069 
00070     public function next() {
00071         $this->current = $this->fetch_next();
00072     }
00073 
00074     public function valid() {
00075         return !empty($this->current);
00076     }
00077 
00078     public function close() {
00079         if ($this->sth) {
00080             $this->sth->closeCursor();
00081             $this->sth = null;
00082         }
00083         $this->current = null;
00084     }
00085 }
 All Data Structures Namespaces Files Functions Variables Enumerations