db_connect

Versions
4.6 – 6
db_connect($url)

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

Code

includes/database.pgsql.inc, line 22

<?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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.