Ruckusing_Adapter_PgSQL_Base::select_one PHP Method

select_one() public method

Select one
public select_one ( string $query ) : array
$query string query to run
return array
    public function select_one($query)
    {
        $this->logger->log($query);
        $query_type = $this->determine_query_type($query);
        if ($query_type == SQL_SELECT || $query_type == SQL_SHOW) {
            $res = pg_query($this->conn, $query);
            if ($this->isError($res)) {
                throw new Ruckusing_Exception(sprintf("Error executing 'query' with:\n%s\n\nReason: %s\n\n", $query, pg_last_error($this->conn)), Ruckusing_Exception::QUERY_ERROR);
            }
            return pg_fetch_assoc($res);
        } else {
            throw new Ruckusing_Exception("Query for select_one() is not one of SELECT or SHOW: {$query}", Ruckusing_Exception::QUERY_ERROR);
        }
    }

Usage Example

 /**
  * test select one
  */
 public function test_select_one()
 {
     $table = $this->adapter->create_table('users');
     $table->column('name', 'string', array('limit' => 20));
     $table->column('age', 'integer');
     $table->finish();
     $id1 = $this->adapter->query(sprintf("INSERT INTO users (name, age) VALUES ('%s', %d) RETURNING \"id\"", 'Taco', 32));
     $this->assertEquals(1, $id1);
     $result = $this->adapter->select_one(sprintf("SELECT * FROM users WHERE name = '%s'", 'Taco'));
     $this->assertEquals(true, is_array($result));
     $this->assertEquals('Taco', $result['name']);
     $this->assertEquals(32, $result['age']);
     $this->drop_table('users');
 }
All Usage Examples Of Ruckusing_Adapter_PgSQL_Base::select_one