PHP POSTGRESQL


M. Jafarian

http://www.informit.com/articles/article.aspx?p=130979&seqNum=3

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s