How Tos > MySQL and Databases

Install and run Postgres

MAMP PRO does not include an instance of Postgres, however it does include the necessary PDO extension to connect with PostGres. Using phpInfo you can confirm the current version of PHP you are using in MAMP PRO has the PDO Postgres extension installed.

MAMP

Download the Postgres database for Mac and install the postgresql-osx.dmg file. You can download postgres here.

MAMP

Your Postgres database will run on port 5432.

MAMP

After installation, by default, you will have a postgres icon on your menu bar. Open the postgres browser.

MAMP

Create a database. (For purposes of the test script below, a “MyPostGresDB” should be created)

MAMP

Here is a simple script for connecting to the Postgres “MyPostGresDB” database. In MAMP PRO, create a host. Add the following script to your index.php file. Make sure you use your own password, and not “pass”.


try {
   $dbh = new PDO('pgsql:host=localhost;port=5432;dbname=MyPostGresDB;user=postgres;password=pass');
   echo "PDO connection object created";
}
catch(PDOException $e)
{
      echo $e->getMessage();
}

?>

When you open this host in your browser you should set the “connection object created” message displayed.