Cached.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php defined('SYSPATH') OR die('No direct script access.');
  2. /**
  3. * Object used for caching the results of select queries. See [Results](/database/results#select-cached) for usage and examples.
  4. *
  5. * @package Kohana/Database
  6. * @category Query/Result
  7. * @author Kohana Team
  8. * @copyright (c) 2009 Kohana Team
  9. * @license http://kohanaphp.com/license
  10. */
  11. class Kohana_Database_Result_Cached extends Database_Result {
  12. public function __construct(array $result, $sql, $as_object = NULL)
  13. {
  14. parent::__construct($result, $sql, $as_object);
  15. // Find the number of rows in the result
  16. $this->_total_rows = count($result);
  17. }
  18. public function __destruct()
  19. {
  20. // Cached results do not use resources
  21. }
  22. public function cached()
  23. {
  24. return $this;
  25. }
  26. public function seek($offset)
  27. {
  28. if ($this->offsetExists($offset))
  29. {
  30. $this->_current_row = $offset;
  31. return TRUE;
  32. }
  33. else
  34. {
  35. return FALSE;
  36. }
  37. }
  38. public function current()
  39. {
  40. // Return an array of the row
  41. return $this->valid() ? $this->_result[$this->_current_row] : NULL;
  42. }
  43. } // End Database_Result_Cached