M. Jafarian

Connecting Postgres and PHP

The connection between PostgreSQL and PHP is made through the use of the pg_Connect() function. This function accepts five parameters: the hostname of the database server, the port on which the postmaster is listening, any connection options, the tty, and the database name. For our purposes, we assume that the PostgreSQL and PHP are installed on the same machine, and that no connection options or tty information are required. In our examples, the call to pg_Connect() looks like this:

// [ ]
$conn = pg_Connect("dbname=[ ]  user=[ ] password=[ ]");

The variable $conn will contain the database connection handle if the function is successful. A sample program looks like this:

<html> <head> <title>Making the Connection</title> </head> <body> <? $conn = pg_Connect("localhost", "5432", "", "", "test"); if (!$conn) {echo "An database connection error occurred.\n"; exit;} else {echo "You have connected to the database successfully.\n";} pg_Close($conn); ?>…

View original post 3,204 more words


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s