MysqliResultset.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 (empty($this->rs)) {
  21. return [];
  22. }
  23. return mysqli_fetch_assoc($this->rs);
  24. }
  25. public function fetchAll()
  26. {
  27. $rows = parent::fetchAll();
  28. if (! is_null($this->found_rows)) {
  29. $rows = array(
  30. 'FOUND_ROWS' => $this->found_rows,
  31. 'ROWS' => $rows,
  32. );
  33. }
  34. return $rows;
  35. }
  36. public function getRowsCount()
  37. {
  38. if (empty($this->rs)) {
  39. return null;
  40. }
  41. if (is_bool($this->rs)) {
  42. return null;
  43. }
  44. return $this->rs->num_rows;
  45. }
  46. public function getfoundRowsCount()
  47. {
  48. return $this->found_rows;
  49. }
  50. }