Sphinx\SphinxClient::getLastError PHP Method

getLastError() public method

Get last error message
public getLastError ( ) : string
return string
    public function getLastError()
    {
        return $this->error;
    }

Usage Example

 /**
  * Search for a query string
  * @param  string  $query   Search query
  * @param  array   $indexes Index list to perform the search
  * @param  boolean $escape  Should the query to be escaped?
  *
  * @return array           Search results
  *
  * @throws EmptyIndexException If $indexes is empty
  * @throws \RuntimeException If seaarch failed
  */
 public function search($query, array $indexes, $escape = true)
 {
     if (empty($indexes)) {
         throw new EmptyIndexException('Try to search with empty indexes');
     }
     if ($escape) {
         $query = $this->sphinx->escapeString($query);
     }
     $qIndex = implode(' ', $indexes);
     $results = $this->sphinx->query($query, $qIndex);
     if (!is_array($results)) {
         throw new \RuntimeException(sprintf('Searching for "%s" failed. Result is not an array. Error "%s"', $query, $this->sphinx->getLastError()));
     }
     if (!isset($results['status'])) {
         throw new \RuntimeException(sprintf('Searching for "%s" failed. Result with no status. Error "%s"', $query, $this->sphinx->getLastError()));
     }
     if ($results['status'] !== SphinxClient::SEARCHD_OK && $results['status'] !== SphinxClient::SEARCHD_WARNING) {
         throw new \RuntimeException(sprintf('Searching for "%s" failed. Result has bad status. Error "%s"', $query, $this->sphinx->getLastError()));
     }
     return $results;
 }
All Usage Examples Of Sphinx\SphinxClient::getLastError