blob: 7f5792ae57aa82739b35ce16deaf62d00614c23a [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 *
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
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, 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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * MySQLi Result Class
31 *
32 * This class extends the parent result class: CI_DB_result
33 *
34 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @link http://codeigniter.com/user_guide/database/
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030037 * @since 1.3
Derek Allard2067d1a2008-11-13 22:59:24 +000038 */
39class CI_DB_mysqli_result extends CI_DB_result {
Barry Mienydd671972010-10-04 16:33:58 +020040
Derek Allard2067d1a2008-11-13 22:59:24 +000041 /**
42 * Number of rows in the result set
43 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020044 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000045 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020046 public function num_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +000047 {
Andrey Andreevc7db6bb2012-07-05 15:11:20 +030048 return is_int($this->num_rows)
49 ? $this->num_rows
50 : $this->num_rows = $this->result_id->num_rows;
Derek Allard2067d1a2008-11-13 22:59:24 +000051 }
Barry Mienydd671972010-10-04 16:33:58 +020052
Derek Allard2067d1a2008-11-13 22:59:24 +000053 // --------------------------------------------------------------------
54
55 /**
56 * Number of fields in the result set
57 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +020058 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +000059 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020060 public function num_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000061 {
Andrey Andreev992f1752012-03-19 16:58:43 +020062 return $this->result_id->field_count;
Derek Allard2067d1a2008-11-13 22:59:24 +000063 }
64
65 // --------------------------------------------------------------------
66
67 /**
68 * Fetch Field Names
69 *
70 * Generates an array of column names
71 *
Derek Allard2067d1a2008-11-13 22:59:24 +000072 * @return array
73 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020074 public function list_fields()
Derek Allard2067d1a2008-11-13 22:59:24 +000075 {
76 $field_names = array();
Chris Buckleyb835a4f2013-01-28 23:35:13 +000077 $this->result_id->field_seek(0);
Andrey Andreev992f1752012-03-19 16:58:43 +020078 while ($field = $this->result_id->fetch_field())
Derek Allard2067d1a2008-11-13 22:59:24 +000079 {
80 $field_names[] = $field->name;
81 }
Barry Mienydd671972010-10-04 16:33:58 +020082
Derek Allard2067d1a2008-11-13 22:59:24 +000083 return $field_names;
84 }
85
86 // --------------------------------------------------------------------
87
88 /**
89 * Field data
90 *
91 * Generates an array of objects containing field meta-data
92 *
Derek Allard2067d1a2008-11-13 22:59:24 +000093 * @return array
94 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +020095 public function field_data()
Derek Allard2067d1a2008-11-13 22:59:24 +000096 {
97 $retval = array();
Andrey Andreev992f1752012-03-19 16:58:43 +020098 $field_data = $this->result_id->fetch_fields();
Andrey Andreeveffd0132012-03-02 12:34:54 +020099 for ($i = 0, $c = count($field_data); $i < $c; $i++)
Barry Mienydd671972010-10-04 16:33:58 +0200100 {
Andrey Andreeveffd0132012-03-02 12:34:54 +0200101 $retval[$i] = new stdClass();
102 $retval[$i]->name = $field_data[$i]->name;
103 $retval[$i]->type = $field_data[$i]->type;
104 $retval[$i]->max_length = $field_data[$i]->max_length;
105 $retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
Andrey Andreev10ecc842012-11-16 01:06:20 +0200106 $retval[$i]->default = $field_data[$i]->def;
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 }
Barry Mienydd671972010-10-04 16:33:58 +0200108
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 return $retval;
110 }
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200111
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 // --------------------------------------------------------------------
113
114 /**
115 * Free the result
116 *
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200117 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200118 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200119 public function free_result()
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 {
121 if (is_object($this->result_id))
122 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200123 $this->result_id->free();
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 $this->result_id = FALSE;
125 }
126 }
127
128 // --------------------------------------------------------------------
129
130 /**
131 * Data Seek
132 *
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300133 * Moves the internal pointer to the desired offset. We call
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 * this internally before fetching results to make sure the
Andrey Andreev8463b912012-11-02 02:16:28 +0200135 * result set starts at zero.
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200137 * @param int $n
Andrey Andreev8f3566f2012-04-12 14:30:05 +0300138 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 */
Andrey Andreev69edc432012-12-04 13:32:16 +0200140 public function data_seek($n = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200142 return $this->result_id->data_seek($n);
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 }
144
145 // --------------------------------------------------------------------
146
147 /**
148 * Result - associative array
149 *
150 * Returns the result set as an array
151 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 * @return array
153 */
Andrey Andreev1ff49e02012-01-27 11:30:41 +0200154 protected function _fetch_assoc()
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 {
Andrey Andreev992f1752012-03-19 16:58:43 +0200156 return $this->result_id->fetch_assoc();
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 }
Barry Mienydd671972010-10-04 16:33:58 +0200158
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 // --------------------------------------------------------------------
160
161 /**
162 * Result - object
163 *
164 * Returns the result set as an object
165 *
Andrey Andreev8463b912012-11-02 02:16:28 +0200166 * @param string $class_name
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 * @return object
168 */
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300169 protected function _fetch_object($class_name = 'stdClass')
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 {
Andrey Andreev9a4f3562012-07-06 11:57:37 +0300171 return $this->result_id->fetch_object($class_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 }
Barry Mienydd671972010-10-04 16:33:58 +0200173
Derek Allard2067d1a2008-11-13 22:59:24 +0000174}
175
Derek Allard2067d1a2008-11-13 22:59:24 +0000176/* End of file mysqli_result.php */
Andrey Andreev67c28712012-03-27 09:20:54 +0300177/* Location: ./system/database/drivers/mysqli/mysqli_result.php */