blob: c1ec4da76cd75915ad586d27712f1d5ab211205b [file] [log] [blame]
Andrey Andreev1ff49e02012-01-27 11:30:41 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev1ff49e02012-01-27 11:30:41 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev1ff49e02012-01-27 11:30:41 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * MySQLi Result Class
30 *
31 * This class extends the parent result class: CI_DB_result
32 *
33 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/database/
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030036 * @since 1.3
Derek Allard2067d1a2008-11-13 22:59:24 +000037 */
38class CI_DB_mysqli_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020039
Derek Allard2067d1a2008-11-13 22:59:24 +000040 /**
41 * Number of rows in the result set
42 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020043 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000044 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020045 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000046 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030047 return is_int($this->num_rows)
48 ? $this->num_rows
49 : $this->num_rows = $this->result_id->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000050 }
Barry Mienydd671972010-10-04 16:33:58 +020051
Derek Allard2067d1a2008-11-13 22:59:24 +000052 // --------------------------------------------------------------------
53
54 /**
55 * Number of fields in the result set
56 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020057 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000058 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020059 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000060 {
Andrey Andreev992f1752012-03-19 16:58:43 +020061 return $this->result_id->field_count;
Derek Allard2067d1a2008-11-13 22:59:24 +000062 }
63
64 // --------------------------------------------------------------------
65
66 /**
67 * Fetch Field Names
68 *
69 * Generates an array of column names
70 *
Derek Allard2067d1a2008-11-13 22:59:24 +000071 * @return array
72 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020073 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000074 {
75 $field_names = array();
Andrey Andreev992f1752012-03-19 16:58:43 +020076 while ($field = $this->result_id->fetch_field())
Derek Allard2067d1a2008-11-13 22:59:24 +000077 {
78 $field_names[] = $field->name;
79 }
Barry Mienydd671972010-10-04 16:33:58 +020080
Derek Allard2067d1a2008-11-13 22:59:24 +000081 return $field_names;
82 }
83
84 // --------------------------------------------------------------------
85
86 /**
87 * Field data
88 *
89 * Generates an array of objects containing field meta-data
90 *
Derek Allard2067d1a2008-11-13 22:59:24 +000091 * @return array
92 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020093 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000094 {
95 $retval = array();
Andrey Andreev992f1752012-03-19 16:58:43 +020096 $field_data = $this->result_id->fetch_fields();
Andrey Andreeveffd0132012-03-02 12:34:54 +020097 for ($i = 0, $c = count($field_data); $i < $c; $i++)
Barry Mienydd671972010-10-04 16:33:58 +020098 {
Andrey Andreeveffd0132012-03-02 12:34:54 +020099 $retval[$i] = new stdClass();
100 $retval[$i]->name = $field_data[$i]->name;
101 $retval[$i]->type = $field_data[$i]->type;
102 $retval[$i]->max_length = $field_data[$i]->max_length;
103 $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
104 $retval[$i]->default = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 }
Barry Mienydd671972010-10-04 16:33:58 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 return $retval;
108 }
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200109
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 // --------------------------------------------------------------------
111
112 /**
113 * Free the result
114 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200115 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200116 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200117 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 {
119 if (is_object($this->result_id))
120 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200121 $this->result_id->free();
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 $this->result_id = FALSE;
123 }
124 }
125
126 // --------------------------------------------------------------------
127
128 /**
129 * Data Seek
130 *
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300131 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * this internally before fetching results to make sure the
133 * result set starts at zero
134 *
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300135 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200137 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200139 return $this->result_id->data_seek($n);
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 }
141
142 // --------------------------------------------------------------------
143
144 /**
145 * Result - associative array
146 *
147 * Returns the result set as an array
148 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 * @return array
150 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200151 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200153 return $this->result_id->fetch_assoc();
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 }
Barry Mienydd671972010-10-04 16:33:58 +0200155
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 // --------------------------------------------------------------------
157
158 /**
159 * Result - object
160 *
161 * Returns the result set as an object
162 *
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300163 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 * @return object
165 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300166 protected function _fetch_object($class_name = 'stdClass')
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300168 return $this->result_id->fetch_object($class_name);
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
Derek Allard2067d1a2008-11-13 22:59:24 +0000173/* End of file mysqli_result.php */
Andrey Andreev67c28712012-03-27 09:20:54 +0300174/* Location: ./system/database/drivers/mysqli/mysqli_result.php */