Website:Postgres

From UGCS
Revision as of 06:26, 19 August 2008 by Jdhutchin@ugcs.caltech.edu (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PostgreSQL

UGCS runs a PostgreSQL version 8.2 database server for its users on poseidon. Each user has a database with the same name as their username, and can log in with their Kerberos tokens. The database is also accessible from any PHP or CGI scripts. If you absolutely need a MySQL database, contact us. We will only consider requests for MySQL databases that have a substantial technical reason for using MySQL over Postgres.

To log in to your database from any UGCS computer, run:

user@to:~$ psql -h postgres

Postgres will automatically use your Kerberos tokens to log you in.

How to connect from PHP

To connect to the database from a PHP script, use pg_connect with a blank URI. The default username, host, and database will work, and you will be authenticated with the kerberos token that your cgi script has.

Using PHP's pgsql extension:

$result = pg_connect("host=postgres user=<username>_cgi dbname=<username>") or die('Could not connect to database: ' . pg_last_error());

Using Pear::MDB2

require_once 'MDB2.php'
$mdb2 =& MDB2::connect('pgsql://<username>_cgi@postgres/<username>');
Personal tools