blob: dc7d9a793afadc754d1b43e7d393f0ca9013016f [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/
36 */
37class CI_DB_mysqli_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020038
Derek Allard2067d1a2008-11-13 22:59:24 +000039 /**
40 * Number of rows in the result set
41 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020042 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000043 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020044 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000045 {
Andrey Andreev992f1752012-03-19 16:58:43 +020046 return $this->result_id->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000047 }
Barry Mienydd671972010-10-04 16:33:58 +020048
Derek Allard2067d1a2008-11-13 22:59:24 +000049 // --------------------------------------------------------------------
50
51 /**
52 * Number of fields in the result set
53 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020054 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000055 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020056 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000057 {
Andrey Andreev992f1752012-03-19 16:58:43 +020058 return $this->result_id->field_count;
Derek Allard2067d1a2008-11-13 22:59:24 +000059 }
60
61 // --------------------------------------------------------------------
62
63 /**
64 * Fetch Field Names
65 *
66 * Generates an array of column names
67 *
Derek Allard2067d1a2008-11-13 22:59:24 +000068 * @return array
69 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020070 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000071 {
72 $field_names = array();
Andrey Andreev992f1752012-03-19 16:58:43 +020073 while ($field = $this->result_id->fetch_field())
Derek Allard2067d1a2008-11-13 22:59:24 +000074 {
75 $field_names[] = $field->name;
76 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 return $field_names;
79 }
80
81 // --------------------------------------------------------------------
82
83 /**
84 * Field data
85 *
86 * Generates an array of objects containing field meta-data
87 *
Derek Allard2067d1a2008-11-13 22:59:24 +000088 * @return array
89 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020090 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
92 $retval = array();
Andrey Andreev992f1752012-03-19 16:58:43 +020093 $field_data = $this->result_id->fetch_fields();
Andrey Andreeveffd0132012-03-02 12:34:54 +020094 for ($i = 0, $c = count($field_data); $i < $c; $i++)
Barry Mienydd671972010-10-04 16:33:58 +020095 {
Andrey Andreeveffd0132012-03-02 12:34:54 +020096 $retval[$i] = new stdClass();
97 $retval[$i]->name = $field_data[$i]->name;
98 $retval[$i]->type = $field_data[$i]->type;
99 $retval[$i]->max_length = $field_data[$i]->max_length;
100 $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
101 $retval[$i]->default = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000102 }
Barry Mienydd671972010-10-04 16:33:58 +0200103
Derek Allard2067d1a2008-11-13 22:59:24 +0000104 return $retval;
105 }
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 // --------------------------------------------------------------------
108
109 /**
110 * Free the result
111 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200112 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200113 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200114 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 {
116 if (is_object($this->result_id))
117 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200118 $this->result_id->free();
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 $this->result_id = FALSE;
120 }
121 }
122
123 // --------------------------------------------------------------------
124
125 /**
126 * Data Seek
127 *
Derek Jones4b9c6292011-07-01 17:40:48 -0500128 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 * this internally before fetching results to make sure the
130 * result set starts at zero
131 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 * @return array
133 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200134 protected function _data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200136 return $this->result_id->data_seek($n);
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 }
138
139 // --------------------------------------------------------------------
140
141 /**
142 * Result - associative array
143 *
144 * Returns the result set as an array
145 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 * @return array
147 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200148 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200150 return $this->result_id->fetch_assoc();
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 }
Barry Mienydd671972010-10-04 16:33:58 +0200152
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 // --------------------------------------------------------------------
154
155 /**
156 * Result - object
157 *
158 * Returns the result set as an object
159 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 * @return object
161 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200162 protected function _fetch_object()
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200164 return $this->result_id->fetch_object();
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 }
Barry Mienydd671972010-10-04 16:33:58 +0200166
Derek Allard2067d1a2008-11-13 22:59:24 +0000167}
168
Derek Allard2067d1a2008-11-13 22:59:24 +0000169/* End of file mysqli_result.php */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200170/* Location: ./system/database/drivers/mysqli/mysqli_result.php */