odbc_result.php 4.6 KB

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