Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?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.
|
Derek Allard | 6838f00 | 2007-10-04 19:29:59 +0000 | [diff] [blame] | 10 | * @license http://www.codeigniter.com/user_guide/license.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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 | */
|
| 27 | class 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 | }
|
| 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 | 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 |
|
| 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 | for ($i = 0; $i < $this->num_fields(); $i++)
|
| 94 | {
|
| 95 | $F = new stdClass();
|
| 96 | $F->name = odbc_field_name($this->result_id, $i);
|
| 97 | $F->type = odbc_field_type($this->result_id, $i);
|
| 98 | $F->max_length = odbc_field_len($this->result_id, $i);
|
| 99 | $F->primary_key = 0;
|
| 100 | $F->default = '';
|
| 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 | odbc_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 FALSE;
|
| 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 | if (function_exists('odbc_fetch_object'))
|
| 154 | {
|
| 155 | return odbc_fetch_array($this->result_id);
|
| 156 | }
|
| 157 | else
|
| 158 | {
|
| 159 | return $this->_odbc_fetch_array($this->result_id);
|
| 160 | }
|
| 161 | }
|
| 162 |
|
| 163 | // --------------------------------------------------------------------
|
| 164 |
|
| 165 | /**
|
| 166 | * Result - object
|
| 167 | *
|
| 168 | * Returns the result set as an object
|
| 169 | *
|
| 170 | * @access private
|
| 171 | * @return object
|
| 172 | */
|
| 173 | function _fetch_object()
|
| 174 | {
|
| 175 | if (function_exists('odbc_fetch_object'))
|
| 176 | {
|
| 177 | return odbc_fetch_object($this->result_id);
|
| 178 | }
|
| 179 | else
|
| 180 | {
|
| 181 | return $this->_odbc_fetch_object($this->result_id);
|
| 182 | }
|
| 183 | }
|
| 184 |
|
| 185 |
|
| 186 | /**
|
| 187 | * Result - object
|
| 188 | *
|
| 189 | * subsititutes the odbc_fetch_object function when
|
| 190 | * not available (odbc_fetch_object requires unixODBC)
|
| 191 | *
|
| 192 | * @access private
|
| 193 | * @return object
|
| 194 | */
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 195 | function _odbc_fetch_object(& $odbc_result) {
|
| 196 | $rs = array();
|
| 197 | $rs_obj = false;
|
| 198 | if (odbc_fetch_into($odbc_result, $rs)) {
|
| 199 | foreach ($rs as $k=>$v) {
|
| 200 | $field_name= odbc_field_name($odbc_result, $k+1);
|
| 201 | $rs_obj->$field_name = $v;
|
| 202 | }
|
| 203 | }
|
| 204 | return $rs_obj;
|
| 205 | }
|
| 206 |
|
| 207 |
|
| 208 | /**
|
| 209 | * Result - array
|
| 210 | *
|
| 211 | * subsititutes the odbc_fetch_array function when
|
| 212 | * not available (odbc_fetch_array requires unixODBC)
|
| 213 | *
|
| 214 | * @access private
|
| 215 | * @return array
|
| 216 | */
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 217 | function _odbc_fetch_array(& $odbc_result) {
|
| 218 | $rs = array();
|
| 219 | $rs_assoc = false;
|
| 220 | if (odbc_fetch_into($odbc_result, $rs)) {
|
| 221 | $rs_assoc=array();
|
| 222 | foreach ($rs as $k=>$v) {
|
| 223 | $field_name= odbc_field_name($odbc_result, $k+1);
|
| 224 | $rs_assoc[$field_name] = $v;
|
| 225 | }
|
| 226 | }
|
| 227 | return $rs_assoc;
|
| 228 | }
|
| 229 |
|
| 230 | }
|
| 231 |
|
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 232 | ?> |