admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame^] | 1 | <?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 | */ |
| 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 | * Field data |
| 57 | * |
| 58 | * Generates an array of objects containing field meta-data |
| 59 | * |
| 60 | * @access public |
| 61 | * @return array |
| 62 | */ |
| 63 | function field_data() |
| 64 | { |
| 65 | $retval = array(); |
| 66 | for ($i = 0; $i < $this->num_fields(); $i++) |
| 67 | { |
| 68 | $F = new stdClass(); |
| 69 | $F->name = odbc_field_name($this->result_id, $i); |
| 70 | $F->type = odbc_field_type($this->result_id, $i); |
| 71 | $F->max_length = odbc_field_len($this->result_id, $i); |
| 72 | $F->primary_key = 0; |
| 73 | $F->default = ''; |
| 74 | |
| 75 | $retval[] = $F; |
| 76 | } |
| 77 | |
| 78 | return $retval; |
| 79 | } |
| 80 | |
| 81 | // -------------------------------------------------------------------- |
| 82 | |
| 83 | /** |
| 84 | * Free the result |
| 85 | * |
| 86 | * @return null |
| 87 | */ |
| 88 | function free_result() |
| 89 | { |
| 90 | if (is_resource($this->result_id)) |
| 91 | { |
| 92 | odbc_free_result($this->result_id); |
| 93 | $this->result_id = FALSE; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // -------------------------------------------------------------------- |
| 98 | |
| 99 | /** |
| 100 | * Result - associative array |
| 101 | * |
| 102 | * Returns the result set as an array |
| 103 | * |
| 104 | * @access private |
| 105 | * @return array |
| 106 | */ |
| 107 | function _fetch_assoc() |
| 108 | { |
| 109 | if (function_exists('odbc_fetch_object')) |
| 110 | { |
| 111 | return odbc_fetch_array($this->result_id); |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | return $this->_odbc_fetch_array($this->result_id); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // -------------------------------------------------------------------- |
| 120 | |
| 121 | /** |
| 122 | * Result - object |
| 123 | * |
| 124 | * Returns the result set as an object |
| 125 | * |
| 126 | * @access private |
| 127 | * @return object |
| 128 | */ |
| 129 | function _fetch_object() |
| 130 | { |
| 131 | if (function_exists('odbc_fetch_object')) |
| 132 | { |
| 133 | return odbc_fetch_object($this->result_id); |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | return $this->_odbc_fetch_object($this->result_id); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
| 142 | /** |
| 143 | * Result - object |
| 144 | * |
| 145 | * subsititutes the odbc_fetch_object function when |
| 146 | * not available (odbc_fetch_object requires unixODBC) |
| 147 | * |
| 148 | * @access private |
| 149 | * @return object |
| 150 | */ |
| 151 | |
| 152 | function _odbc_fetch_object(& $odbc_result) { |
| 153 | $rs = array(); |
| 154 | $rs_obj = false; |
| 155 | if (odbc_fetch_into($odbc_result, $rs)) { |
| 156 | foreach ($rs as $k=>$v) { |
| 157 | $field_name= odbc_field_name($odbc_result, $k+1); |
| 158 | $rs_obj->$field_name = $v; |
| 159 | } |
| 160 | } |
| 161 | return $rs_obj; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | /** |
| 166 | * Result - array |
| 167 | * |
| 168 | * subsititutes the odbc_fetch_array function when |
| 169 | * not available (odbc_fetch_array requires unixODBC) |
| 170 | * |
| 171 | * @access private |
| 172 | * @return array |
| 173 | */ |
| 174 | |
| 175 | function _odbc_fetch_array(& $odbc_result) { |
| 176 | $rs = array(); |
| 177 | $rs_assoc = false; |
| 178 | if (odbc_fetch_into($odbc_result, $rs)) { |
| 179 | $rs_assoc=array(); |
| 180 | foreach ($rs as $k=>$v) { |
| 181 | $field_name= odbc_field_name($odbc_result, $k+1); |
| 182 | $rs_assoc[$field_name] = $v; |
| 183 | } |
| 184 | } |
| 185 | return $rs_assoc; |
| 186 | } |
| 187 | |
| 188 | } |
| 189 | |
| 190 | ?> |