blob: 385209c562b30136886e36bc6ce854466992357f [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
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, pMachine, 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 * ODBC 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_odbc_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 @odbc_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 @odbc_num_fields($this->result_id);
51 }
adminab4f61b2006-09-25 22:12:32 +000052
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 field_names()
64 {
65 $field_names = array();
66 for ($i = 0; $i < $this->num_fields(); $i++)
67 {
68 $field_names[] = odbc_field_name($this->result_id, $i);
69 }
70
71 return $field_names;
72 }
73
admin7b613c72006-09-24 18:05:17 +000074 // --------------------------------------------------------------------
75
76 /**
77 * Field data
78 *
79 * Generates an array of objects containing field meta-data
80 *
81 * @access public
82 * @return array
83 */
84 function field_data()
85 {
86 $retval = array();
87 for ($i = 0; $i < $this->num_fields(); $i++)
88 {
89 $F = new stdClass();
90 $F->name = odbc_field_name($this->result_id, $i);
91 $F->type = odbc_field_type($this->result_id, $i);
92 $F->max_length = odbc_field_len($this->result_id, $i);
93 $F->primary_key = 0;
94 $F->default = '';
95
96 $retval[] = $F;
97 }
98
99 return $retval;
100 }
101
102 // --------------------------------------------------------------------
103
104 /**
105 * Free the result
106 *
107 * @return null
108 */
109 function free_result()
110 {
111 if (is_resource($this->result_id))
112 {
113 odbc_free_result($this->result_id);
114 $this->result_id = FALSE;
115 }
116 }
117
118 // --------------------------------------------------------------------
119
120 /**
121 * Result - associative array
122 *
123 * Returns the result set as an array
124 *
125 * @access private
126 * @return array
127 */
128 function _fetch_assoc()
129 {
130 if (function_exists('odbc_fetch_object'))
131 {
132 return odbc_fetch_array($this->result_id);
133 }
134 else
135 {
136 return $this->_odbc_fetch_array($this->result_id);
137 }
138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Result - object
144 *
145 * Returns the result set as an object
146 *
147 * @access private
148 * @return object
149 */
150 function _fetch_object()
151 {
152 if (function_exists('odbc_fetch_object'))
153 {
154 return odbc_fetch_object($this->result_id);
155 }
156 else
157 {
158 return $this->_odbc_fetch_object($this->result_id);
159 }
160 }
161
162
163 /**
164 * Result - object
165 *
166 * subsititutes the odbc_fetch_object function when
167 * not available (odbc_fetch_object requires unixODBC)
168 *
169 * @access private
170 * @return object
171 */
172
173 function _odbc_fetch_object(& $odbc_result) {
174 $rs = array();
175 $rs_obj = false;
176 if (odbc_fetch_into($odbc_result, $rs)) {
177 foreach ($rs as $k=>$v) {
178 $field_name= odbc_field_name($odbc_result, $k+1);
179 $rs_obj->$field_name = $v;
180 }
181 }
182 return $rs_obj;
183 }
184
185
186 /**
187 * Result - array
188 *
189 * subsititutes the odbc_fetch_array function when
190 * not available (odbc_fetch_array requires unixODBC)
191 *
192 * @access private
193 * @return array
194 */
195
196 function _odbc_fetch_array(& $odbc_result) {
197 $rs = array();
198 $rs_assoc = false;
199 if (odbc_fetch_into($odbc_result, $rs)) {
200 $rs_assoc=array();
201 foreach ($rs as $k=>$v) {
202 $field_name= odbc_field_name($odbc_result, $k+1);
203 $rs_assoc[$field_name] = $v;
204 }
205 }
206 return $rs_assoc;
207 }
208
209}
210
211?>