blob: 392a663694ce63e2c2b08268c458c8584c095212 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev1ff49e02012-01-27 11:30:41 +02008 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02009 * Copyright (c) 2014, British Columbia Institute of Technology
Andrey Andreev1ff49e02012-01-27 11:30:41 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
Derek Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * @package CodeIgniter
30 * @author EllisLab Dev Team
darwinel871754a2014-02-11 17:34:57 +010031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020032 * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/)
33 * @license http://opensource.org/licenses/MIT MIT License
34 * @link http://codeigniter.com
35 * @since Version 1.3.0
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @filesource
37 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
41 * MySQLi Result Class
42 *
43 * This class extends the parent result class: CI_DB_result
44 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020045 * @package CodeIgniter
46 * @subpackage Drivers
Derek Allard2067d1a2008-11-13 22:59:24 +000047 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050048 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000049 * @link http://codeigniter.com/user_guide/database/
50 */
51class CI_DB_mysqli_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020052
Derek Allard2067d1a2008-11-13 22:59:24 +000053 /**
54 * Number of rows in the result set
55 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020056 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000057 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020058 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000059 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030060 return is_int($this->num_rows)
61 ? $this->num_rows
62 : $this->num_rows = $this->result_id->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000063 }
Barry Mienydd671972010-10-04 16:33:58 +020064
Derek Allard2067d1a2008-11-13 22:59:24 +000065 // --------------------------------------------------------------------
66
67 /**
68 * Number of fields in the result set
69 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020070 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000071 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020072 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000073 {
Andrey Andreev992f1752012-03-19 16:58:43 +020074 return $this->result_id->field_count;
Derek Allard2067d1a2008-11-13 22:59:24 +000075 }
76
77 // --------------------------------------------------------------------
78
79 /**
80 * Fetch Field Names
81 *
82 * Generates an array of column names
83 *
Derek Allard2067d1a2008-11-13 22:59:24 +000084 * @return array
85 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020086 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000087 {
88 $field_names = array();
Chris Buckleyb835a4f2013-01-28 23:35:13 +000089 $this->result_id->field_seek(0);
Andrey Andreev992f1752012-03-19 16:58:43 +020090 while ($field = $this->result_id->fetch_field())
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
92 $field_names[] = $field->name;
93 }
Barry Mienydd671972010-10-04 16:33:58 +020094
Derek Allard2067d1a2008-11-13 22:59:24 +000095 return $field_names;
96 }
97
98 // --------------------------------------------------------------------
99
100 /**
101 * Field data
102 *
103 * Generates an array of objects containing field meta-data
104 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 * @return array
106 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200107 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 {
109 $retval = array();
Andrey Andreev992f1752012-03-19 16:58:43 +0200110 $field_data = $this->result_id->fetch_fields();
Andrey Andreeveffd0132012-03-02 12:34:54 +0200111 for ($i = 0, $c = count($field_data); $i < $c; $i++)
Barry Mienydd671972010-10-04 16:33:58 +0200112 {
Andrey Andreeveffd0132012-03-02 12:34:54 +0200113 $retval[$i] = new stdClass();
114 $retval[$i]->name = $field_data[$i]->name;
115 $retval[$i]->type = $field_data[$i]->type;
116 $retval[$i]->max_length = $field_data[$i]->max_length;
117 $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
Andrey Andreev10ecc842012-11-16 01:06:20 +0200118 $retval[$i]->default = $field_data[$i]->def;
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 }
Barry Mienydd671972010-10-04 16:33:58 +0200120
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 return $retval;
122 }
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200123
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 // --------------------------------------------------------------------
125
126 /**
127 * Free the result
128 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200129 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200130 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200131 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 {
133 if (is_object($this->result_id))
134 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200135 $this->result_id->free();
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 $this->result_id = FALSE;
137 }
138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Data Seek
144 *
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300145 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 * this internally before fetching results to make sure the
Andrey Andreev8463b912012-11-02 02:16:28 +0200147 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200149 * @param int $n
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300150 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 */
Andrey Andreev69edc432012-12-04 13:32:16 +0200152 public function data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200154 return $this->result_id->data_seek($n);
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 }
156
157 // --------------------------------------------------------------------
158
159 /**
160 * Result - associative array
161 *
162 * Returns the result set as an array
163 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 * @return array
165 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200166 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200168 return $this->result_id->fetch_assoc();
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 }
Barry Mienydd671972010-10-04 16:33:58 +0200170
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 // --------------------------------------------------------------------
172
173 /**
174 * Result - object
175 *
176 * Returns the result set as an object
177 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200178 * @param string $class_name
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 * @return object
180 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300181 protected function _fetch_object($class_name = 'stdClass')
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300183 return $this->result_id->fetch_object($class_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 }
Barry Mienydd671972010-10-04 16:33:58 +0200185
Derek Allard2067d1a2008-11-13 22:59:24 +0000186}
187
Derek Allard2067d1a2008-11-13 22:59:24 +0000188/* End of file mysqli_result.php */
Andrey Andreev67c28712012-03-27 09:20:54 +0300189/* Location: ./system/database/drivers/mysqli/mysqli_result.php */