pdo_result.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 2.1.2
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * PDO 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_pdo_result extends CI_DB_result {
  27. public $num_rows;
  28. /**
  29. * Number of rows in the result set
  30. *
  31. * @return int
  32. */
  33. public function num_rows()
  34. {
  35. if (is_int($this->num_rows))
  36. {
  37. return $this->num_rows;
  38. }
  39. elseif (($this->num_rows = $this->result_id->rowCount()) > 0)
  40. {
  41. return $this->num_rows;
  42. }
  43. $this->num_rows = count($this->result_id->fetchAll());
  44. $this->result_id->execute();
  45. return $this->num_rows;
  46. }
  47. // --------------------------------------------------------------------
  48. /**
  49. * Number of fields in the result set
  50. *
  51. * @access public
  52. * @return integer
  53. */
  54. function num_fields()
  55. {
  56. return $this->result_id->columnCount();
  57. }
  58. // --------------------------------------------------------------------
  59. /**
  60. * Fetch Field Names
  61. *
  62. * Generates an array of column names
  63. *
  64. * @access public
  65. * @return array
  66. */
  67. function list_fields()
  68. {
  69. if ($this->db->db_debug)
  70. {
  71. return $this->db->display_error('db_unsuported_feature');
  72. }
  73. return FALSE;
  74. }
  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. $data = array();
  87. try
  88. {
  89. for($i = 0; $i < $this->num_fields(); $i++)
  90. {
  91. $data[] = $this->result_id->getColumnMeta($i);
  92. }
  93. return $data;
  94. }
  95. catch (Exception $e)
  96. {
  97. if ($this->db->db_debug)
  98. {
  99. return $this->db->display_error('db_unsuported_feature');
  100. }
  101. return FALSE;
  102. }
  103. }
  104. // --------------------------------------------------------------------
  105. /**
  106. * Free the result
  107. *
  108. * @return null
  109. */
  110. function free_result()
  111. {
  112. if (is_object($this->result_id))
  113. {
  114. $this->result_id = FALSE;
  115. }
  116. }
  117. // --------------------------------------------------------------------
  118. /**
  119. * Data Seek
  120. *
  121. * Moves the internal pointer to the desired offset. We call
  122. * this internally before fetching results to make sure the
  123. * result set starts at zero
  124. *
  125. * @access private
  126. * @return array
  127. */
  128. function _data_seek($n = 0)
  129. {
  130. return FALSE;
  131. }
  132. // --------------------------------------------------------------------
  133. /**
  134. * Result - associative array
  135. *
  136. * Returns the result set as an array
  137. *
  138. * @access private
  139. * @return array
  140. */
  141. function _fetch_assoc()
  142. {
  143. return $this->result_id->fetch(PDO::FETCH_ASSOC);
  144. }
  145. // --------------------------------------------------------------------
  146. /**
  147. * Result - object
  148. *
  149. * Returns the result set as an object
  150. *
  151. * @access private
  152. * @return object
  153. */
  154. function _fetch_object()
  155. {
  156. return $this->result_id->fetchObject();
  157. }
  158. }
  159. /* End of file pdo_result.php */
  160. /* Location: ./system/database/drivers/pdo/pdo_result.php */