pdo_result.php 3.4 KB

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