mysql_result.php 3.5 KB

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