/halogy/database/drivers/odbc/odbc_result.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 228 lines · 92 code · 27 blank · 109 comment · 8 complexity · fb1cd244852baa3b6e297798dd66f22f MD5 · raw file

  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 ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * ODBC Result Class
  18. *
  19. * This class extends the parent result class: CI_DB_result
  20. *
  21. * @category Database
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/database/
  24. */
  25. class CI_DB_odbc_result extends CI_DB_result {
  26. /**
  27. * Number of rows in the result set
  28. *
  29. * @access public
  30. * @return integer
  31. */
  32. function num_rows()
  33. {
  34. return @odbc_num_rows($this->result_id);
  35. }
  36. // --------------------------------------------------------------------
  37. /**
  38. * Number of fields in the result set
  39. *
  40. * @access public
  41. * @return integer
  42. */
  43. function num_fields()
  44. {
  45. return @odbc_num_fields($this->result_id);
  46. }
  47. // --------------------------------------------------------------------
  48. /**
  49. * Fetch Field Names
  50. *
  51. * Generates an array of column names
  52. *
  53. * @access public
  54. * @return array
  55. */
  56. function list_fields()
  57. {
  58. $field_names = array();
  59. for ($i = 0; $i < $this->num_fields(); $i++)
  60. {
  61. $field_names[] = odbc_field_name($this->result_id, $i);
  62. }
  63. return $field_names;
  64. }
  65. // --------------------------------------------------------------------
  66. /**
  67. * Field data
  68. *
  69. * Generates an array of objects containing field meta-data
  70. *
  71. * @access public
  72. * @return array
  73. */
  74. function field_data()
  75. {
  76. $retval = array();
  77. for ($i = 0; $i < $this->num_fields(); $i++)
  78. {
  79. $F = new stdClass();
  80. $F->name = odbc_field_name($this->result_id, $i);
  81. $F->type = odbc_field_type($this->result_id, $i);
  82. $F->max_length = odbc_field_len($this->result_id, $i);
  83. $F->primary_key = 0;
  84. $F->default = '';
  85. $retval[] = $F;
  86. }
  87. return $retval;
  88. }
  89. // --------------------------------------------------------------------
  90. /**
  91. * Free the result
  92. *
  93. * @return null
  94. */
  95. function free_result()
  96. {
  97. if (is_resource($this->result_id))
  98. {
  99. odbc_free_result($this->result_id);
  100. $this->result_id = FALSE;
  101. }
  102. }
  103. // --------------------------------------------------------------------
  104. /**
  105. * Data Seek
  106. *
  107. * Moves the internal pointer to the desired offset. We call
  108. * this internally before fetching results to make sure the
  109. * result set starts at zero
  110. *
  111. * @access private
  112. * @return array
  113. */
  114. function _data_seek($n = 0)
  115. {
  116. return FALSE;
  117. }
  118. // --------------------------------------------------------------------
  119. /**
  120. * Result - associative array
  121. *
  122. * Returns the result set as an array
  123. *
  124. * @access private
  125. * @return array
  126. */
  127. function _fetch_assoc()
  128. {
  129. if (function_exists('odbc_fetch_object'))
  130. {
  131. return odbc_fetch_array($this->result_id);
  132. }
  133. else
  134. {
  135. return $this->_odbc_fetch_array($this->result_id);
  136. }
  137. }
  138. // --------------------------------------------------------------------
  139. /**
  140. * Result - object
  141. *
  142. * Returns the result set as an object
  143. *
  144. * @access private
  145. * @return object
  146. */
  147. function _fetch_object()
  148. {
  149. if (function_exists('odbc_fetch_object'))
  150. {
  151. return odbc_fetch_object($this->result_id);
  152. }
  153. else
  154. {
  155. return $this->_odbc_fetch_object($this->result_id);
  156. }
  157. }
  158. /**
  159. * Result - object
  160. *
  161. * subsititutes the odbc_fetch_object function when
  162. * not available (odbc_fetch_object requires unixODBC)
  163. *
  164. * @access private
  165. * @return object
  166. */
  167. function _odbc_fetch_object(& $odbc_result) {
  168. $rs = array();
  169. $rs_obj = false;
  170. if (odbc_fetch_into($odbc_result, $rs)) {
  171. foreach ($rs as $k=>$v) {
  172. $field_name= odbc_field_name($odbc_result, $k+1);
  173. $rs_obj->$field_name = $v;
  174. }
  175. }
  176. return $rs_obj;
  177. }
  178. /**
  179. * Result - array
  180. *
  181. * subsititutes the odbc_fetch_array function when
  182. * not available (odbc_fetch_array requires unixODBC)
  183. *
  184. * @access private
  185. * @return array
  186. */
  187. function _odbc_fetch_array(& $odbc_result) {
  188. $rs = array();
  189. $rs_assoc = false;
  190. if (odbc_fetch_into($odbc_result, $rs)) {
  191. $rs_assoc=array();
  192. foreach ($rs as $k=>$v) {
  193. $field_name= odbc_field_name($odbc_result, $k+1);
  194. $rs_assoc[$field_name] = $v;
  195. }
  196. }
  197. return $rs_assoc;
  198. }
  199. }
  200. /* End of file odbc_result.php */
  201. /* Location: ./system/database/drivers/odbc/odbc_result.php */