function db_connect in Drupal 6
Same name in this branch
- 6 includes/database.mysqli.inc \db_connect()
- 6 includes/database.mysql.inc \db_connect()
- 6 includes/database.pgsql.inc \db_connect()
Same name and namespace in other branches
- 4 includes/database.mysqli.inc \db_connect()
- 4 includes/database.mysql.inc \db_connect()
- 4 includes/database.pgsql.inc \db_connect()
- 5 includes/database.mysqli.inc \db_connect()
- 5 includes/database.mysql.inc \db_connect()
- 5 includes/database.pgsql.inc \db_connect()
Initialize a database connection.
Related topics
1 call to db_connect()
- db_set_active in includes/
database.inc - Activate a database for future queries.
File
- includes/
database.pgsql.inc, line 46 - Database interface code for PostgreSQL database servers.
Code
function db_connect($url) {
// Check if PostgreSQL support is present in PHP
if (!function_exists('pg_connect')) {
_db_error_page('Unable to use the PostgreSQL database because the PostgreSQL extension for PHP is not installed. Check your <code>php.ini</code> to see how you can enable it.');
}
$url = parse_url($url);
$conn_string = '';
// Decode urlencoded information in the db connection string
if (isset($url['user'])) {
$conn_string .= ' user=' . urldecode($url['user']);
}
if (isset($url['pass'])) {
$conn_string .= ' password=' . urldecode($url['pass']);
}
if (isset($url['host'])) {
$conn_string .= ' host=' . urldecode($url['host']);
}
if (isset($url['path'])) {
$conn_string .= ' dbname=' . substr(urldecode($url['path']), 1);
}
if (isset($url['port'])) {
$conn_string .= ' port=' . urldecode($url['port']);
}
// pg_last_error() does not return a useful error message for database
// connection errors. We must turn on error tracking to get at a good error
// message, which will be stored in $php_errormsg.
$track_errors_previous = ini_get('track_errors');
ini_set('track_errors', 1);
$connection = @pg_connect($conn_string);
if (!$connection) {
require_once './includes/unicode.inc';
_db_error_page(decode_entities($php_errormsg));
}
// Restore error tracking setting
ini_set('track_errors', $track_errors_previous);
pg_query($connection, "set client_encoding=\"UTF8\"");
return $connection;
}