Ruckusing_Adapter_PgSQL_Base::database_exists PHP Method

database_exists() public method

Check if a db exists
public database_exists ( string $db ) : boolean
$db string the db name
return boolean
    public function database_exists($db)
    {
        $sql = sprintf("SELECT datname FROM pg_database WHERE datname = '%s'", $db);
        $result = $this->select_one($sql);
        return count($result) == 1 && $result['datname'] == $db;
    }

Usage Example

 /**
  * test dropping database
  */
 public function test_database_droppage()
 {
     $db = "test_db";
     //create it
     $this->assertEquals(true, $this->adapter->create_database($db));
     $this->assertEquals(true, $this->adapter->database_exists($db));
     //drop it
     $this->assertEquals(true, $this->adapter->drop_database($db));
     $this->assertEquals(false, $this->adapter->database_exists($db));
 }