blob: 7dcd5cb0e3a6ba585c22b4d3a2da9924a6147ad4 [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, EllisLab, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// --------------------------------------------------------------------
17
18/**
19 * MySQL Result Class
20 *
21 * This class extends the parent result class: CI_DB_result
22 *
23 * @category Database
24 * @author Rick Ellis
25 * @link http://www.codeigniter.com/user_guide/database/
26 */
27class CI_DB_mysql_result extends CI_DB_result {
28
29 /**
30 * Number of rows in the result set
31 *
32 * @access public
33 * @return integer
34 */
35 function num_rows()
36 {
37 return @mysql_num_rows($this->result_id);
38 }
39
40 // --------------------------------------------------------------------
41
42 /**
43 * Number of fields in the result set
44 *
45 * @access public
46 * @return integer
47 */
48 function num_fields()
49 {
50 return @mysql_num_fields($this->result_id);
51 }
52
53 // --------------------------------------------------------------------
54
55 /**
56 * Fetch Field Names
57 *
58 * Generates an array of column names
59 *
60 * @access public
61 * @return array
62 */
63 function list_fields()
64 {
65 $field_names = array();
66 while ($field = mysql_fetch_field($this->result_id))
67 {
68 $field_names[] = $field->name;
69 }
70
71 return $field_names;
72 }
73
74 // Deprecated
75 function field_names()
76 {
77 return $this->list_fields();
78 }
79
80 // --------------------------------------------------------------------
81
82 /**
83 * Field data
84 *
85 * Generates an array of objects containing field meta-data
86 *
87 * @access public
88 * @return array
89 */
90 function field_data()
91 {
92 $retval = array();
93 while ($field = mysql_fetch_field($this->result_id))
94 {
95 $F = new stdClass();
96 $F->name = $field->name;
97 $F->type = $field->type;
98 $F->default = $field->def;
99 $F->max_length = $field->max_length;
100 $F->primary_key = $field->primary_key;
101
102 $retval[] = $F;
103 }
104
105 return $retval;
106 }
107
108 // --------------------------------------------------------------------
109
110 /**
111 * Free the result
112 *
113 * @return null
114 */
115 function free_result()
116 {
117 if (is_resource($this->result_id))
118 {
119 mysql_free_result($this->result_id);
120 $this->result_id = FALSE;
121 }
122 }
123
124 // --------------------------------------------------------------------
125
126 /**
127 * Data Seek
128 *
129 * Moves the internal pointer to the desired offset. We call
130 * this internally before fetching results to make sure the
131 * result set starts at zero
132 *
133 * @access private
134 * @return array
135 */
136 function _data_seek($n = 0)
137 {
138 return mysql_data_seek($this->result_id, $n);
139 }
140
141 // --------------------------------------------------------------------
142
143 /**
144 * Result - associative array
145 *
146 * Returns the result set as an array
147 *
148 * @access private
149 * @return array
150 */
151 function _fetch_assoc()
152 {
153 return mysql_fetch_assoc($this->result_id);
154 }
155
156 // --------------------------------------------------------------------
157
158 /**
159 * Result - object
160 *
161 * Returns the result set as an object
162 *
163 * @access private
164 * @return object
165 */
166 function _fetch_object()
167 {
168 return mysql_fetch_object($this->result_id);
169 }
170
171}
172
admin7b613c72006-09-24 18:05:17 +0000173?>