Using PostgreSQL: Difference between revisions
Rockinroel (talk | contribs) (Created page with "= Creating a database = You can create one or more PostgreSQL databases in [https://ucc.ulyssis.org UCC]. The first database you create will have the same name as your usern...") |
Rockinroel (talk | contribs) mNo edit summary |
||
Line 34: | Line 34: | ||
database, and your username is "foo", your password is "password" and your database name is "foo": | database, and your username is "foo", your password is "password" and your database name is "foo": | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
$connection = pg_connect("host=pgsql. | $connection = pg_connect("host=pgsql.ulyssis.org user=foo password=password db=foo"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== PDO == | == PDO == |
Revision as of 10:45, 11 May 2014
Creating a database
You can create one or more PostgreSQL databases in UCC.
The first database you create will have the same name as your username. Subsequent databases will be prefixed with "username_".
Managing your database
- The easiest way to manage your database is using phpPgAdmin.
- You can also access it via the command line with:
psql -h pgsql.ulyssis.org
Connecting to the database
You can connect to the database with the following details:
- Host:
pgsql.ulyssis.org
- Login: your ULYSSIS username
- Password: the PostgreSQL password you chose in UCC
- Database: the database you created in UCC
Note that some CMSs will assume that you use "localhost" as the host, and will hide the host option under advanced settings in the installation process. If you can't find anywhere to enter the hostname, look under advanced settings.
Connection string
If you are programming your application yourself, PostgreSQL often uses the following connection format:
host=$host user=$username password=$password db=$dbname
Where you replace the parts starting with $
with the above connection details.
pg_connect
If you are using PHP's pg_connect to connect to the database, and your username is "foo", your password is "password" and your database name is "foo":
$connection = pg_connect("host=pgsql.ulyssis.org user=foo password=password db=foo");
PDO
If you want to connect using PDO, your username is "foo", your password is "password" and your database is "foo":
$pdo = new PDO('pgsql:host=pgsql.ulyssis.org;dbname=foo', 'foo', 'password');