mysql_result.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. * MySQL 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_mysql_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 @mysql_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 @mysql_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. while ($field = mysql_fetch_field($this->result_id))
  61. {
  62. $field_names[] = $field->name;
  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. while ($field = mysql_fetch_object($this->result_id))
  79. {
  80. preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
  81. $type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
  82. $length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
  83. $F = new stdClass();
  84. $F->name = $field->Field;
  85. $F->type = $type;
  86. $F->default = $field->Default;
  87. $F->max_length = $length;
  88. $F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
  89. $retval[] = $F;
  90. }
  91. return $retval;
  92. }
  93. // --------------------------------------------------------------------
  94. /**
  95. * Free the result
  96. *
  97. * @return null
  98. */
  99. function free_result()
  100. {
  101. if (is_resource($this->result_id))
  102. {
  103. mysql_free_result($this->result_id);
  104. $this->result_id = FALSE;
  105. }
  106. }
  107. // --------------------------------------------------------------------
  108. /**
  109. * Data Seek
  110. *
  111. * Moves the internal pointer to the desired offset. We call
  112. * this internally before fetching results to make sure the
  113. * result set starts at zero
  114. *
  115. * @access private
  116. * @return array
  117. */
  118. function _data_seek($n = 0)
  119. {
  120. return mysql_data_seek($this->result_id, $n);
  121. }
  122. // --------------------------------------------------------------------
  123. /**
  124. * Result - associative array
  125. *
  126. * Returns the result set as an array
  127. *
  128. * @access private
  129. * @return array
  130. */
  131. function _fetch_assoc()
  132. {
  133. return mysql_fetch_assoc($this->result_id);
  134. }
  135. // --------------------------------------------------------------------
  136. /**
  137. * Result - object
  138. *
  139. * Returns the result set as an object
  140. *
  141. * @access private
  142. * @return object
  143. */
  144. function _fetch_object()
  145. {
  146. return mysql_fetch_object($this->result_id);
  147. }
  148. }
  149. /* End of file mysql_result.php */
  150. /* Location: ./system/database/drivers/mysql/mysql_result.php */