Using PostgreSQL Database in Your Application

To connect to PostgreSQL database, you need to specify the following in your application.

  • Hostname: localhost or

  • Database name: specify the name of database you want to connect to. For example: u777_database.

  • Username: the name of database. In other words, this is the same as your database name above.

  • Password: the password of this database where can be set inside SiteManager.

The following examples illustrates how to use PostgreSQL database inside your application, assuming the database to be used is u777_database with password 'PASSWORD'.


You can also see examples inside SiteManager. Go to Database Server and then click examples for the database in question.

Using PostgreSQL Database With PHP

// Code taken from PHP manual

$username = "u777_database";
$password = "PASSWORD";
$hostname = "localhost";

// Connecting to database
$link = pg_connect("dbname=u777_database ".
    "user=u777_database password=DATABASE");

// Performing SQL query
$result = pg_exec($sql);

// Closing connection

Using PostgreSQL Database With Perl

# code taken from Perl DBI documentation

use DBI;

# connecting to database
my $username = 'u777_database';
my $password = 'PASSWORD';
my $dbh = DBI->connect("DBI:Pg:$username",
    "$username", "$password");

# executing a single query without result
my $rv = $dbh->do($sql);

# retrieving result from a query
my $arrayref = $dbh->selectall_arrayref($sql);

# disconnect from database
my $rc = $dbh->disconnect();

Using PostgreSQL Database With Python

import pgdb

# connecting to database
username = "u777_database"
password = "PASSWORD"
hostname = "localhost"
conn = pgdb.Connect(host=hostname, user=username,
    passwd=password, db=username)

# create result/cursor object
cursor = conn.cursor()

# perform a query

# get result set
result = cursor.fetchall()

# close the connection

Using PostgreSQL Database With ASP

connect_string = "Driver={Postgres}; Server=localhost; " & _
    "UID=u777_database; PWD=PASSWORD"

' opening connection to database
set dbConn = server.createObject("ADODB.connection") connect_string

' perform a query
Set recordset = dbConn.Execute(SQL)

' closing connection

Copyright © 2003

. .