Result.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * MySQLi database result. See [Results](/database/results) for usage and examples.
  4. *
  5. * @package Kohana/Database
  6. * @category Query/Result
  7. * @author Kohana Team
  8. * @copyright (c) Kohana Team
  9. * @license https://koseven.ga/LICENSE.md
  10. */
  11. class Kohana_Database_MySQLi_Result extends Database_Result {
  12. protected $_internal_row = 0;
  13. public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
  14. {
  15. parent::__construct($result, $sql, $as_object, $params);
  16. // Find the number of rows in the result
  17. $this->_total_rows = $result->num_rows;
  18. }
  19. public function __destruct()
  20. {
  21. if (is_resource($this->_result))
  22. {
  23. $this->_result->free();
  24. }
  25. }
  26. #[\ReturnTypeWillChange]
  27. public function seek($offset)
  28. {
  29. if ($this->offsetExists($offset) AND $this->_result->data_seek($offset))
  30. {
  31. // Set the current row to the offset
  32. $this->_current_row = $this->_internal_row = $offset;
  33. return TRUE;
  34. }
  35. else
  36. {
  37. return FALSE;
  38. }
  39. }
  40. #[\ReturnTypeWillChange]
  41. public function current()
  42. {
  43. if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
  44. return NULL;
  45. // Increment internal row for optimization assuming rows are fetched in order
  46. $this->_internal_row++;
  47. if ($this->_as_object === TRUE)
  48. {
  49. // Return an stdClass
  50. return $this->_result->fetch_object();
  51. }
  52. elseif (is_string($this->_as_object))
  53. {
  54. // Return an object of given class name
  55. return $this->_result->fetch_object($this->_as_object, (array) $this->_object_params);
  56. }
  57. else
  58. {
  59. // Return an array of the row
  60. return $this->_result->fetch_assoc();
  61. }
  62. }
  63. } // End Database_MySQLi_Result_Select