MDL-31689 fix moodle_database:execute() description
[moodle.git] / lib / dml / mysqli_native_moodle_recordset.php
blobfae004332478e5f089e2d473d3c2ef36342669a2
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 /**
20 * Mysqli specific recordset.
22 * @package core
23 * @subpackage dml
24 * @copyright 2008 Petr Skoda (http://skodak.org)
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 require_once($CFG->libdir.'/dml/moodle_recordset.php');
32 /**
33 * Mysqli specific moodle recordset class
35 class mysqli_native_moodle_recordset extends moodle_recordset {
37 protected $result;
38 protected $current;
40 public function __construct($result) {
41 $this->result = $result;
42 $this->current = $this->fetch_next();
45 public function __destruct() {
46 $this->close();
49 private function fetch_next() {
50 if ($row = $this->result->fetch_assoc()) {
51 $row = array_change_key_case($row, CASE_LOWER);
53 return $row;
56 public function current() {
57 return (object)$this->current;
60 public function key() {
61 /// return first column value as key
62 if (!$this->current) {
63 return false;
65 $key = reset($this->current);
66 return $key;
69 public function next() {
70 $this->current = $this->fetch_next();
73 public function valid() {
74 return !empty($this->current);
77 public function close() {
78 if ($this->result) {
79 $this->result->close();
80 $this->result = null;
82 $this->current = null;