MysqliResultset.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace KarmaFW\Database\Sql\Drivers\Mysqli;
  3. use \KarmaFW\Database\Sql\SqlResultset;
  4. use \KarmaFW\Database\Sql\SqlResultsetInterface;
  5. class MysqliResultset extends SqlResultset implements SqlResultsetInterface
  6. {
  7. protected $found_rows = null;
  8. function __construct($rs, $found_rows=null)
  9. {
  10. $this->rs = $rs;
  11. $this->found_rows = $found_rows;
  12. }
  13. public function fetchColumn($column_name)
  14. {
  15. $row = $this->fetchOne();
  16. return isset($row[$column_name]) ? $row[$column_name] : null;
  17. }
  18. public function fetchOne()
  19. {
  20. if (is_bool($this->rs)) {
  21. //debug_print_backtrace();
  22. }
  23. if (empty($this->rs) || $this->rs === true) {
  24. return [];
  25. }
  26. return mysqli_fetch_assoc($this->rs);
  27. }
  28. public function fetchAll()
  29. {
  30. $rows = parent::fetchAll();
  31. if (! is_null($this->found_rows)) {
  32. /*
  33. $rows = array(
  34. 'found_rows' => $this->found_rows,
  35. 'data' => $rows,
  36. );
  37. */
  38. }
  39. return $rows;
  40. }
  41. public function getRowsCount()
  42. {
  43. if (empty($this->rs)) {
  44. return null;
  45. }
  46. if (is_bool($this->rs)) {
  47. return null;
  48. }
  49. return $this->rs->num_rows;
  50. }
  51. public function getfoundRowsCount()
  52. {
  53. return $this->found_rows;
  54. }
  55. }