db_connect
Definition
db_connect($url)
includes/database.pgsql.inc, line 22
Description
Initialize a database connection.
Note that you can change the pg_connect) call to pg_pconnect) if you want to use persistent connections. This is not recommended on shared hosts, and might require additional database/webserver tuning. It can increase performance, however, when the overhead to connect to your database is high (e.g. your database and web server live on different machines).
Related topics
| Name | Description |
|---|---|
| Database abstraction layer | Allow the use of different database servers using the same code base. |
Code
<?php
function db_connect($url) {
$url = parse_url($url);
$conn_string = ' user='. $url['user'] .' dbname='. substr($url['path'], 1) .' password='. $url['pass'] . ' host=' . $url['host'];
$conn_string .= isset($url['port']) ? ' port=' . $url['port'] : '';
$connection = pg_connect($conn_string) or die(pg_last_error());
return $connection;
}
?> 