|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CodeIgniter |
|
4
|
|
|
* |
|
5
|
|
|
* An open source application development framework for PHP |
|
6
|
|
|
* |
|
7
|
|
|
* This content is released under the MIT License (MIT) |
|
8
|
|
|
* |
|
9
|
|
|
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology |
|
10
|
|
|
* |
|
11
|
|
|
* 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: |
|
17
|
|
|
* |
|
18
|
|
|
* 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 |
|
31
|
|
|
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
|
32
|
|
|
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) |
|
33
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
|
34
|
|
|
* @link https://codeigniter.com |
|
35
|
|
|
* @since Version 1.3.0 |
|
36
|
|
|
* @filesource |
|
37
|
|
|
*/ |
|
38
|
|
|
namespace Rioxygen\CiCoreDatabase\Mysql; |
|
39
|
|
|
|
|
40
|
|
|
use Rioxygen\CiCoreDatabase\CI_DB_result; |
|
41
|
|
|
use \stdClass; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* MySQLi Result Class |
|
45
|
|
|
* |
|
46
|
|
|
* This class extends the parent result class: CI_DB_result |
|
47
|
|
|
* |
|
48
|
|
|
* @package CodeIgniter |
|
49
|
|
|
* @subpackage Drivers |
|
50
|
|
|
* @category Database |
|
51
|
|
|
* @author EllisLab Dev Team |
|
52
|
|
|
* @link https://codeigniter.com/user_guide/database/ |
|
53
|
|
|
*/ |
|
54
|
|
|
class CI_DB_mysqli_result extends CI_DB_result { |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Number of rows in the result set |
|
58
|
|
|
* |
|
59
|
|
|
* @return int |
|
60
|
|
|
*/ |
|
61
|
|
|
public function num_rows() |
|
62
|
|
|
{ |
|
63
|
|
|
return is_int($this->num_rows) |
|
|
|
|
|
|
64
|
|
|
? $this->num_rows |
|
65
|
|
|
: $this->num_rows = $this->result_id->num_rows; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
// -------------------------------------------------------------------- |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Number of fields in the result set |
|
72
|
|
|
* |
|
73
|
|
|
* @return int |
|
74
|
|
|
*/ |
|
75
|
|
|
public function num_fields() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->result_id->field_count; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// -------------------------------------------------------------------- |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Fetch Field Names |
|
84
|
|
|
* |
|
85
|
|
|
* Generates an array of column names |
|
86
|
|
|
* |
|
87
|
|
|
* @return array |
|
88
|
|
|
*/ |
|
89
|
|
|
public function list_fields() |
|
90
|
|
|
{ |
|
91
|
|
|
$field_names = array(); |
|
92
|
|
|
$this->result_id->field_seek(0); |
|
93
|
|
|
while ($field = $this->result_id->fetch_field()) |
|
94
|
|
|
{ |
|
95
|
|
|
$field_names[] = $field->name; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $field_names; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// -------------------------------------------------------------------- |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Field data |
|
105
|
|
|
* |
|
106
|
|
|
* Generates an array of objects containing field meta-data |
|
107
|
|
|
* |
|
108
|
|
|
* @return array |
|
109
|
|
|
*/ |
|
110
|
|
|
public function field_data() |
|
111
|
|
|
{ |
|
112
|
|
|
$retval = array(); |
|
113
|
|
|
$field_data = $this->result_id->fetch_fields(); |
|
114
|
|
|
for ($i = 0, $c = count($field_data); $i < $c; $i++) |
|
115
|
|
|
{ |
|
116
|
|
|
$retval[$i] = new stdClass(); |
|
117
|
|
|
$retval[$i]->name = $field_data[$i]->name; |
|
118
|
|
|
$retval[$i]->type = static::_get_field_type($field_data[$i]->type); |
|
119
|
|
|
$retval[$i]->max_length = $field_data[$i]->max_length; |
|
120
|
|
|
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG); |
|
121
|
|
|
$retval[$i]->default = $field_data[$i]->def; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return $retval; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
// -------------------------------------------------------------------- |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Get field type |
|
131
|
|
|
* |
|
132
|
|
|
* Extracts field type info from the bitflags returned by |
|
133
|
|
|
* mysqli_result::fetch_fields() |
|
134
|
|
|
* |
|
135
|
|
|
* @used-by CI_DB_mysqli_result::field_data() |
|
136
|
|
|
* @param int $flags |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
|
private static function _get_field_type($flags) |
|
140
|
|
|
{ |
|
141
|
|
|
static $map; |
|
142
|
|
|
isset($map) OR $map = array( |
|
143
|
|
|
MYSQLI_TYPE_DECIMAL => 'decimal', |
|
144
|
|
|
MYSQLI_TYPE_BIT => 'bit', |
|
145
|
|
|
MYSQLI_TYPE_TINY => 'tinyint', |
|
146
|
|
|
MYSQLI_TYPE_SHORT => 'smallint', |
|
147
|
|
|
MYSQLI_TYPE_INT24 => 'mediumint', |
|
148
|
|
|
MYSQLI_TYPE_LONG => 'int', |
|
149
|
|
|
MYSQLI_TYPE_LONGLONG => 'bigint', |
|
150
|
|
|
MYSQLI_TYPE_FLOAT => 'float', |
|
151
|
|
|
MYSQLI_TYPE_DOUBLE => 'double', |
|
152
|
|
|
MYSQLI_TYPE_TIMESTAMP => 'timestamp', |
|
153
|
|
|
MYSQLI_TYPE_DATE => 'date', |
|
154
|
|
|
MYSQLI_TYPE_TIME => 'time', |
|
155
|
|
|
MYSQLI_TYPE_DATETIME => 'datetime', |
|
156
|
|
|
MYSQLI_TYPE_YEAR => 'year', |
|
157
|
|
|
MYSQLI_TYPE_NEWDATE => 'date', |
|
158
|
|
|
MYSQLI_TYPE_INTERVAL => 'interval', |
|
159
|
|
|
MYSQLI_TYPE_ENUM => 'enum', |
|
160
|
|
|
MYSQLI_TYPE_SET => 'set', |
|
161
|
|
|
MYSQLI_TYPE_TINY_BLOB => 'tinyblob', |
|
162
|
|
|
MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob', |
|
163
|
|
|
MYSQLI_TYPE_BLOB => 'blob', |
|
164
|
|
|
MYSQLI_TYPE_LONG_BLOB => 'longblob', |
|
165
|
|
|
MYSQLI_TYPE_STRING => 'char', |
|
166
|
|
|
MYSQLI_TYPE_VAR_STRING => 'varchar', |
|
167
|
|
|
MYSQLI_TYPE_GEOMETRY => 'geometry' |
|
168
|
|
|
); |
|
169
|
|
|
|
|
170
|
|
|
foreach ($map as $flag => $name) |
|
171
|
|
|
{ |
|
172
|
|
|
if ($flags & $flag) |
|
173
|
|
|
{ |
|
174
|
|
|
return $name; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
return $flags; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
// -------------------------------------------------------------------- |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Free the result |
|
185
|
|
|
* |
|
186
|
|
|
* @return void |
|
187
|
|
|
*/ |
|
188
|
|
|
public function free_result() |
|
189
|
|
|
{ |
|
190
|
|
|
if (is_object($this->result_id)) |
|
191
|
|
|
{ |
|
192
|
|
|
$this->result_id->free(); |
|
193
|
|
|
$this->result_id = FALSE; |
|
|
|
|
|
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
// -------------------------------------------------------------------- |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Data Seek |
|
201
|
|
|
* |
|
202
|
|
|
* Moves the internal pointer to the desired offset. We call |
|
203
|
|
|
* this internally before fetching results to make sure the |
|
204
|
|
|
* result set starts at zero. |
|
205
|
|
|
* |
|
206
|
|
|
* @param int $n |
|
207
|
|
|
* @return bool |
|
208
|
|
|
*/ |
|
209
|
|
|
public function data_seek($n = 0) |
|
210
|
|
|
{ |
|
211
|
|
|
return $this->result_id->data_seek($n); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
// -------------------------------------------------------------------- |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Result - associative array |
|
218
|
|
|
* |
|
219
|
|
|
* Returns the result set as an array |
|
220
|
|
|
* |
|
221
|
|
|
* @return array |
|
222
|
|
|
*/ |
|
223
|
|
|
protected function _fetch_assoc() |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->result_id->fetch_assoc(); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
// -------------------------------------------------------------------- |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Result - object |
|
232
|
|
|
* |
|
233
|
|
|
* Returns the result set as an object |
|
234
|
|
|
* |
|
235
|
|
|
* @param string $class_name |
|
236
|
|
|
* @return object |
|
237
|
|
|
*/ |
|
238
|
|
|
protected function _fetch_object($class_name = 'stdClass') |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->result_id->fetch_object($class_name); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
} |
|
244
|
|
|
|