Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * 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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * MySQLi Result Class |
| 30 | * |
| 31 | * This class extends the parent result class: CI_DB_result |
| 32 | * |
| 33 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
| 37 | class CI_DB_mysqli_result extends CI_DB_result { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 38 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | /** |
| 40 | * Number of rows in the result set |
| 41 | * |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 42 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 43 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 44 | public function num_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 45 | { |
| 46 | return @mysqli_num_rows($this->result_id); |
| 47 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 48 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | // -------------------------------------------------------------------- |
| 50 | |
| 51 | /** |
| 52 | * Number of fields in the result set |
| 53 | * |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 54 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 55 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 56 | public function num_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 57 | { |
| 58 | return @mysqli_num_fields($this->result_id); |
| 59 | } |
| 60 | |
| 61 | // -------------------------------------------------------------------- |
| 62 | |
| 63 | /** |
| 64 | * Fetch Field Names |
| 65 | * |
| 66 | * Generates an array of column names |
| 67 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 68 | * @return array |
| 69 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 70 | public function list_fields() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | { |
| 72 | $field_names = array(); |
| 73 | while ($field = mysqli_fetch_field($this->result_id)) |
| 74 | { |
| 75 | $field_names[] = $field->name; |
| 76 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 77 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | return $field_names; |
| 79 | } |
| 80 | |
| 81 | // -------------------------------------------------------------------- |
| 82 | |
| 83 | /** |
| 84 | * Field data |
| 85 | * |
| 86 | * Generates an array of objects containing field meta-data |
| 87 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 88 | * @return array |
| 89 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 90 | public function field_data() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | { |
| 92 | $retval = array(); |
danmontgomery | fc75645 | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 93 | while ($field = mysqli_fetch_object($this->result_id)) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 94 | { |
Phil Sturgeon | 659baa9 | 2011-10-27 13:24:53 +0100 | [diff] [blame] | 95 | preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches); |
danmontgomery | fc75645 | 2011-08-21 15:31:22 -0400 | [diff] [blame] | 96 | |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 97 | $F = new stdClass(); |
| 98 | $F->name = $field->Field; |
| 99 | $F->type = ( ! empty($matches[1])) ? $matches[1] : NULL; |
| 100 | $F->default = $field->Default; |
| 101 | $F->max_length = ( ! empty($matches[2])) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL; |
| 102 | $F->primary_key = (int) ($field->Key === 'PRI'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 103 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 104 | $retval[] = $F; |
| 105 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 106 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | return $retval; |
| 108 | } |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 109 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | // -------------------------------------------------------------------- |
| 111 | |
| 112 | /** |
| 113 | * Free the result |
| 114 | * |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 115 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 116 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 117 | public function free_result() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | { |
| 119 | if (is_object($this->result_id)) |
| 120 | { |
| 121 | mysqli_free_result($this->result_id); |
| 122 | $this->result_id = FALSE; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // -------------------------------------------------------------------- |
| 127 | |
| 128 | /** |
| 129 | * Data Seek |
| 130 | * |
Derek Jones | 4b9c629 | 2011-07-01 17:40:48 -0500 | [diff] [blame] | 131 | * Moves the internal pointer to the desired offset. We call |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | * this internally before fetching results to make sure the |
| 133 | * result set starts at zero |
| 134 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | * @return array |
| 136 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 137 | protected function _data_seek($n = 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | { |
| 139 | return mysqli_data_seek($this->result_id, $n); |
| 140 | } |
| 141 | |
| 142 | // -------------------------------------------------------------------- |
| 143 | |
| 144 | /** |
| 145 | * Result - associative array |
| 146 | * |
| 147 | * Returns the result set as an array |
| 148 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 149 | * @return array |
| 150 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 151 | protected function _fetch_assoc() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 152 | { |
| 153 | return mysqli_fetch_assoc($this->result_id); |
| 154 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 155 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 156 | // -------------------------------------------------------------------- |
| 157 | |
| 158 | /** |
| 159 | * Result - object |
| 160 | * |
| 161 | * Returns the result set as an object |
| 162 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 163 | * @return object |
| 164 | */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 165 | protected function _fetch_object() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | { |
| 167 | return mysqli_fetch_object($this->result_id); |
| 168 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 169 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | /* End of file mysqli_result.php */ |
Andrey Andreev | 1ff49e0 | 2012-01-27 11:30:41 +0200 | [diff] [blame^] | 173 | /* Location: ./system/database/drivers/mysqli/mysqli_result.php */ |