<?php
require_once "config.php";

if ( !function_exists('get_dbconnection') ) 
{
	function get_dbconnection ()
	{
		$conn = pg_connect("options=--application_name=eoQUAL_PHP host=".$GLOBALS["DB_IP"]." port=".$GLOBALS["DB_PORT"]." dbname=".$GLOBALS["DB_NAME"]." user=".$GLOBALS["DB_USER"]." password=".$GLOBALS["DB_PWD"]) or die('connection failed');
		return $conn;
	}

	function get_dbconnectionRIS ()
	{
		if ( $GLOBALS["DB_IP_RIS"] =="" )
			return null;

		$conn = pg_connect("options=--application_name=eoRIS_PHP host=".$GLOBALS["DB_IP_RIS"]." port=".$GLOBALS["DB_PORT_RIS"]." dbname=".$GLOBALS["DB_NAME_RIS"]." user=".$GLOBALS["DB_USER_RIS"]." password=".$GLOBALS["DB_PWD_RIS"]) or die('connection failed');
		return $conn;
	}
}


if ( !function_exists('getPDO') )
{
	function getPDO()
	{
		$db_host=$GLOBALS['DB_IP'];
		$db_name=$GLOBALS['DB_NAME'];
		$db_user=$GLOBALS['DB_USER'];
		$db_password=$GLOBALS['DB_PWD'];
		$db_port=$GLOBALS['DB_PORT'];
    	$pdo = new PDO("pgsql:host=$db_host;port=$db_port;dbname=$db_name", $db_user, $db_password);
    	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    	return $pdo;
    }
 }

?>
