Driver_Database_Driver_Postgre::_get_dsn
null Driver_Database_Driver_Postgre::_get_dsn( )
File: ./drivers/database/postgre/postgre.class.php
protected function _get_dsn($database, $hostname, $port, $socket, $username, $password, $persistent, $config)
{
$dsn = '';
if (false!==strpos($hostname, '/'))
{
// If UNIX sockets are used, we shouldn't set a port
$port = '';
}
$hostname === '' OR $dsn = 'host='. $hostname .' ';
if (!empty($port) && ctype_digit($port))
{
$dsn .= 'port='. $port .' ';
}
if ($username!=='')
{
$dsn .= 'user='. $username .' ';
/* An empty password is valid!
*
* $db['password'] = NULL must be done in order to ignore it.
*/
$password === null OR $dsn .= "password='" . $password ."' ";
}
$database === '' OR $dsn .= 'dbname='. $database .' ';
/* We don't have these options as elements in our standard configuration
* array, but they might be set by parse_url() if the configuration was
* provided via string. Example:
*
* postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
*/
foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
{
if (isset($config[$key]) && is_string($config[$key]) && $config[$key] !== '')
{
$dsn .= $key."='". $config[$key] ."' ";
}
}
$dsn = rtrim($dsn);
return $dsn;
}