Contao\Database\Statement::query PHP Method

query() public method

Directly send a query string to the database
public query ( string $strQuery = '' ) : Result | Statement
$strQuery string The query string
return Result | Statement The result object or the statement object if there is no result set
    public function query($strQuery = '')
    {
        if (!empty($strQuery)) {
            $this->strQuery = trim($strQuery);
        }
        // Make sure there is a query string
        if ($this->strQuery == '') {
            throw new \Exception('Empty query string');
        }
        // Execute the query
        $this->statement = $this->resConnection->executeQuery($this->strQuery);
        // No result set available
        if (strncasecmp($this->strQuery, 'SELECT', 6) !== 0 && strncasecmp($this->strQuery, 'SHOW', 4) !== 0) {
            return $this;
        }
        // Instantiate a result object
        return new \Database\Result($this->statement, $this->strQuery);
    }

Usage Example

Beispiel #1
0
 /**
  * Execute a raw query and return a Database\Result object
  *
  * @param string $strQuery The query string
  *
  * @return Database\Result|object The Database\Result object
  */
 public function query($strQuery)
 {
     $objStatement = new \Database\Statement($this->resConnection, $this->blnDisableAutocommit);
     return $objStatement->query($strQuery);
 }