Ejemplo n.º 1
0
 /**
  * Performs the actual query on the database and returns the results
  * as an associative array. If there a no results, returns an empty array.
  *
  * @return Array
  * @throws \Exception
  */
 public function execute()
 {
     $this->validate();
     $query = $this->searchQuery;
     $countQuery = $this->searchQuery->composeCountQuery();
     $countResult = $this->db->query($countQuery);
     if (!$countResult) {
         throw new QueryFailedException('No valid result from Database, Error: ' . $this->db->error, $this->db->errno);
     }
     $result = $this->db->query($query);
     if (!$result) {
         throw new QueryFailedException('No valid result from Database, Error: ' . $this->db->error, $this->db->errno);
     }
     $this->searchResult = $result->fetch_all(MYSQLI_ASSOC);
     $this->numRows = count($this->searchResult);
     $this->totalRows = $countResult->fetch_row()[0];
     return $this->searchResult;
 }