src/PostGres.php
public function query($query, $return_set = false, $buffered = true)
    {
        $this->_result = null;

        $query = trim($query);

        $this->_result = @pg_query($this->_connection, $query);

        // Invalid Query

        if (!$this->_result) {

            $error_message = @\pg_last_error($this->_connection); //NOSONAR

            throw new ConnectionException('An error occurred while
					attempting to query the PostGres server: ' . $error_message);

        } // Valid Query

        else {

            $num_rows = @\pg_num_rows($this->_result);
            $matches = [];

            /** @noinspection PhpUnusedLocalVariableInspection */
            $match_count = preg_match(
                '/^([\w]+)(?:[\W]+|$)/i', $query, $matches);
            assert('$match_count === 1');

            $query_type = strtoupper($matches[1]);

            switch ($query_type) {

                case 'SELECT':
                case 'SHOW':
                case 'EXPLAIN':
                case 'DESCRIBE':

                    if ($return_set && $num_rows >= 1) {

                        return new PostGresResultSet($this->_result, $buffered);
                    } elseif ($num_rows == 1) {

                        return new PostGresResultRow($this->_result);
                    } elseif ($num_rows > 1) {

                        return new PostGresResultSet($this->_result, $buffered);
                    } else {

                        return false;
                    }

                    break;

                case 'DELETE':
                case 'INSERT':
                case 'REPLACE':
                case 'UPDATE':

                    return $this->getAffectedRows();

                    break;

                case 'START':
                case 'COMMIT':
                case 'ROLLBACK':
                case 'SET':

                    return true;

                    break;

                default:

                    return false;
            }
        }
    }
public function query($query, $return_set = false, $buffered = true)
    {
        $this->_result = null;

        $query = trim($query);

        $this->_result = @pg_query($this->_connection, $query);

        // Invalid Query

        if (!$this->_result) {

            $error_message = @\pg_last_error($this->_connection); //NOSONAR

            throw new ConnectionException('An error occurred while
					attempting to query the PostGres server: ' . $error_message);

        } // Valid Query

        else {

            $num_rows = @\pg_num_rows($this->_result);
            $matches = [];

            /** @noinspection PhpUnusedLocalVariableInspection */
            $match_count = preg_match(
                '/^([\w]+)(?:[\W]+|$)/i', $query, $matches);
            assert('$match_count === 1');

            $query_type = strtoupper($matches[1]);

            switch ($query_type) {

                case 'SELECT':
                case 'SHOW':
                case 'EXPLAIN':
                case 'DESCRIBE':

                    if ($return_set && $num_rows >= 1) {

                        return new PostGresResultSet($this->_result, $buffered);
                    } elseif ($num_rows == 1) {

                        return new PostGresResultRow($this->_result);
                    } elseif ($num_rows > 1) {

                        return new PostGresResultSet($this->_result, $buffered);
                    } else {

                        return false;
                    }

                    break;

                case 'DELETE':
                case 'INSERT':
                case 'REPLACE':
                case 'UPDATE':

                    return $this->getAffectedRows();

                    break;

                case 'START':
                case 'COMMIT':
                case 'ROLLBACK':
                case 'SET':

                    return true;

                    break;

                default:

                    return false;
            }
        }
    }
public function query ( $ query , $ return_set = false , $ buffered = true ) { $ this -> _result = null ; $ query = trim ( $ query ) ; $ this -> _result = @ pg_query ( $ this -> _connection , $ query ) ; // Invalid Query if ( ! $ this -> _result ) { $ error_message = @ \ pg_last_error ( $ this -> _connection ) ; //NOSONAR throw new ConnectionException ( 'An error occurred while
					attempting to query the PostGres server: ' . $ error_message ) ; } // Valid Query else { $ num_rows = @ \ pg_num_rows ( $ this -> _result ) ; $ matches = [ ] ; /** @noinspection PhpUnusedLocalVariableInspection */ $ match_count = preg_match ( '/^([\w]+)(?:[\W]+|$)/i' , $ query , $ matches ) ; assert ( '$match_count === 1' ) ; $ query_type = strtoupper ( $ matches [ 1 ] ) ; switch ( $ query_type ) { case 'SELECT' : case 'SHOW' : case 'EXPLAIN' : case 'DESCRIBE' : if ( $ return_set && $ num_rows >= 1 ) { return new PostGresResultSet ( $ this -> _result , $ buffered ) ; } elseif ( $ num_rows == 1 ) { return new PostGresResultRow ( $ this -> _result ) ; } elseif ( $ num_rows > 1 ) { return new PostGresResultSet ( $ this -> _result , $ buffered ) ; } else { return false ; } break ; case 'DELETE' : case 'INSERT' : case 'REPLACE' : case 'UPDATE' : return $ this -> getAffectedRows ( ) ; break ; case 'START' : case 'COMMIT' : case 'ROLLBACK' : case 'SET' : return true ; break ; default : return false ; } } }
Send a query to the PostGres server.

<p>For <strong>SELECT</strong>-queries: If the query has a result, this
method returns either {@link SQLResultRow} or {@link SQLResultSet}
instance, depending on the number of results. If no results are available
the method returns <em>false</em>.</p>

<p>For all other queries: If the query is successful, the amount of
affected rows is returned, else <em>false</em> is returned.</p>

@param string $query
@param boolean $return_set
@param boolean $buffered
@return SQLResult|integer|boolean
@throws ConnectionException
@see SQL::query()
Send a query to the PostGres server .