Exemple #1
0
 /**
  * Connect to database
  *
  * @param array $options
  * @return array
  */
 public function connect($options)
 {
     $result = ['version' => null, 'status' => 0, 'error' => [], 'errno' => 0, 'success' => false];
     // we could pass an array or connection string right a way
     if (is_array($options)) {
         $str = 'host=' . $options['host'] . ' port=' . $options['port'] . ' dbname=' . $options['dbname'] . ' user='******'username'] . ' password='******'password'];
     } else {
         $str = $options;
     }
     $connection = pg_connect($str);
     if ($connection !== false) {
         $this->db_resource = $connection;
         $this->connect_options = $options;
         $this->commit_status = 0;
         pg_set_error_verbosity($connection, PGSQL_ERRORS_VERBOSE);
         pg_set_client_encoding($connection, 'UNICODE');
         $result['version'] = pg_version($connection);
         $result['status'] = pg_connection_status($connection) === PGSQL_CONNECTION_OK ? 1 : 0;
         $result['success'] = true;
     } else {
         $result['error'][] = 'db::connect() : Could not connect to database server!';
         $result['errno'] = 1;
     }
     return $result;
 }
Exemple #2
0
 function __construct($params)
 {
     $this->dbconn = pg_pconnect($params['server']);
     if (false === $this->dbconn) {
         throw new \Pg\Exception(pg_last_error());
     }
     if (isset($params['type_converter'])) {
         $this->typeConverter = $params['type_converter'];
     } else {
         $this->typeConverter = new \Pg\TypeConverter();
     }
     pg_set_error_verbosity($this->dbconn, PGSQL_ERRORS_VERBOSE);
 }
Exemple #3
0
 protected function connect(&$config)
 {
     if ($this->conn !== null) {
         throw new reException('postgres db: already connected');
     }
     if (($this->conn = pg_connect($config['connection_string'])) === false) {
         throw new reException('postgres db connect failed: ' . pg_last_error(null));
     }
     pg_set_error_verbosity($this->conn, PGSQL_ERRORS_VERBOSE);
     if (isset($config['query_log'])) {
         $this->query_log = $config['query_log'];
     }
 }
 /**
  * @return PgSQL
  **/
 public function connect()
 {
     $conn = "host={$this->hostname} user={$this->username}" . ($this->password ? " password={$this->password}" : null) . ($this->basename ? " dbname={$this->basename}" : null) . ($this->port ? " port={$this->port}" : null);
     if ($this->persistent) {
         $this->link = pg_pconnect($conn);
     } else {
         $this->link = pg_connect($conn);
     }
     if (!$this->link) {
         throw new DatabaseException('can not connect to PostgreSQL server: ' . pg_errormessage());
     }
     if ($this->encoding) {
         $this->setDbEncoding();
     }
     pg_set_error_verbosity($this->link, PGSQL_ERRORS_VERBOSE);
     return $this;
 }
 function connect($force = false)
 {
     if ($this->isConnected() && !$force) {
         return $this;
     }
     $connectionParameters = array();
     $connectionParameters['host'] = (string) $this->getHost();
     $connectionParameters['user'] = (string) $this->getUser();
     if ($this->getPassword()) {
         $connectionParameters['password'] = $this->getPassword();
     }
     if ($this->getDBName()) {
         $connectionParameters['dbname'] = $this->getDBName();
     }
     if ($this->getPort()) {
         $connectionParameters['port'] = $this->getPort();
     }
     $connectionString = array();
     foreach ($connectionParameters as $key => $value) {
         $connectionString[] = $key . '=' . $this->getDialect()->quoteValue($value);
     }
     $connectionString = join(' ', $connectionString);
     try {
         if ($this->isPersistent()) {
             LoggerPool::log(parent::LOG_VERBOSE, 'obtaining a persistent connection to postgresql: %s', $connectionString);
             $this->link = pg_pconnect($connectionString);
         } else {
             LoggerPool::log(parent::LOG_VERBOSE, 'obtaining a new connection to postgresql: %s', $connectionString);
             $this->link = pg_pconnect($connectionString, $force ? PGSQL_CONNECT_FORCE_NEW : null);
         }
     } catch (ExecutionContextException $e) {
         LoggerPool::log(parent::LOG_VERBOSE, 'connection to postgresql failed: %s', $e->getMessage());
         throw new DBConnectionException($this, "can not connect using {$connectionString}: {$e->getMessage()}");
     }
     $this->preparedStatements = array();
     if ($this->getEncoding()) {
         $this->setEncoding($this->getEncoding());
     }
     pg_set_error_verbosity($this->link, PGSQL_ERRORS_TERSE);
     return $this;
 }
Exemple #6
0
 /**
  * Connects to a database.
  * @return void
  * @throws Dibi\Exception
  */
 public function connect(array &$config)
 {
     $error = NULL;
     if (isset($config['resource'])) {
         $this->connection = $config['resource'];
     } else {
         $config += ['charset' => 'utf8'];
         if (isset($config['string'])) {
             $string = $config['string'];
         } else {
             $string = '';
             Dibi\Helpers::alias($config, 'user', 'username');
             Dibi\Helpers::alias($config, 'dbname', 'database');
             foreach (['host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service'] as $key) {
                 if (isset($config[$key])) {
                     $string .= $key . '=' . $config[$key] . ' ';
                 }
             }
         }
         set_error_handler(function ($severity, $message) use(&$error) {
             $error = $message;
         });
         if (empty($config['persistent'])) {
             $this->connection = pg_connect($string, PGSQL_CONNECT_FORCE_NEW);
         } else {
             $this->connection = pg_pconnect($string, PGSQL_CONNECT_FORCE_NEW);
         }
         restore_error_handler();
     }
     if (!is_resource($this->connection)) {
         throw new Dibi\DriverException($error ?: 'Connecting error.');
     }
     pg_set_error_verbosity($this->connection, PGSQL_ERRORS_VERBOSE);
     if (isset($config['charset']) && pg_set_client_encoding($this->connection, $config['charset'])) {
         throw self::createException(pg_last_error($this->connection));
     }
     if (isset($config['schema'])) {
         $this->query('SET search_path TO "' . $config['schema'] . '"');
     }
 }
Exemple #7
0
 /**
  * @param ConnectionSettings
  */
 public function __construct($connectionSettings, ConnectionFactory $connectionFactory = null)
 {
     if (!$connectionSettings instanceof ConnectionSettings) {
         throw new BadTypeException($connectionSettings, 'Bond\\Pg\\ConnectionSettings');
     }
     $this->connectionSettings = $connectionSettings;
     $connectionString = $this->connectionSettings->getConnectionString();
     if (!($resource = @pg_connect($connectionString, PGSQL_CONNECT_FORCE_NEW))) {
         $error = error_get_last();
         throw new UnableToConnectException($connectionString, $error['message'], $connectionSettings->jsonSerialize());
     }
     self::$instances[] = $this;
     $this->terminated = false;
     pg_set_error_verbosity($resource, PGSQL_ERRORS_VERBOSE);
     // search path -- this must be sql safe
     // possible sql injection vuln here -- setting must be sql injection safe
     if (isset($connectionSettings->search_path)) {
         pg_query("SET search_path TO {$connectionSettings->search_path};");
     }
     $this->resource = $resource;
     $this->connectionFactory = $connectionFactory;
 }
Exemple #8
0
 /**
  * Explicitly connects to the database
  *
  * @return $this
  * @throws exceptions\ConnectionException
  */
 public function connect()
 {
     if ($this->_resource) {
         return $this;
     }
     $connectionWarnings = array();
     set_error_handler(function ($errno, $errstr) use(&$connectionWarnings) {
         $connectionWarnings[] = $errstr;
         return true;
     }, E_WARNING);
     $this->_resource = pg_connect($this->_connectionString, PGSQL_CONNECT_FORCE_NEW);
     restore_error_handler();
     if (false === $this->_resource) {
         throw new exceptions\ConnectionException(__METHOD__ . ': ' . implode("\n", $connectionWarnings));
     }
     pg_set_error_verbosity($this->_resource, PGSQL_ERRORS_VERBOSE);
     return $this;
 }
function uf_select_voucher($ls_chevau)
{
	////////////////////////////////////////////////////////////////////////////////////////////////
	//
	// -Funcion que verifica que retorna true si el vaucher introducido ya existe
	// Autor: Ing. Laura Cabre
	//
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	$dat=$_SESSION["la_empresa"];
	$ls_codemp=$dat["codemp"];		
	$ls_sql="SELECT chevau 
			FROM scb_movbco 
			WHERE chevau='$ls_chevau' AND codope='CH' and  codemp='$ls_codemp'";		
	$rs_mov=$this->io_sql->select($ls_sql);
	if(($rs_mov===false))
	{
		pg_set_error_verbosity($this->io_sql->conn, PGSQL_ERRORS_TERSE);
		$ls_x=pg_last_error($this->io_sql->conn);
		$this->is_msg_error="Error en uf_select_voucher,".$this->io_sql->message;
		print $this->is_msg_error;
		return false;
	}
	else
	{
		if($row=$this->io_sql->fetch_row($rs_mov))
		{
			if($row["chevau"]!="")
				return true;
			else
				return false;
		}
		else
		{
			return false;
		}	
	}	
}
Exemple #10
0
 /**
  * Connects to the database if needed.
  *
  * @return  void  Returns void if the database connected successfully.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function connect()
 {
     if ($this->connection) {
         return;
     }
     // Make sure the postgresql extension for PHP is installed and enabled.
     if (!static::isSupported()) {
         throw new UnsupportedAdapterException('PHP extension pg_connect is not available.');
     }
     /*
      * pg_connect() takes the port as separate argument. Therefore, we
      * have to extract it from the host string (if povided).
      */
     // Check for empty port
     if (!$this->options['port']) {
         // Port is empty or not set via options, check for port annotation (:) in the host string
         $tmp = substr(strstr($this->options['host'], ':'), 1);
         if (!empty($tmp)) {
             // Get the port number
             if (is_numeric($tmp)) {
                 $this->options['port'] = $tmp;
             }
             // Extract the host name
             $this->options['host'] = substr($this->options['host'], 0, strlen($this->options['host']) - (strlen($tmp) + 1));
             // This will take care of the following notation: ":5432"
             if ($this->options['host'] == '') {
                 $this->options['host'] = 'localhost';
             }
         } else {
             $this->options['port'] = '5432';
         }
     }
     // Build the DSN for the connection.
     $dsn = "host={$this->options['host']} port={$this->options['port']} dbname={$this->options['database']} " . "user={$this->options['user']} password={$this->options['password']}";
     // Attempt to connect to the server.
     if (!($this->connection = @pg_connect($dsn))) {
         $this->log(Log\LogLevel::ERROR, 'Error connecting to PGSQL database.');
         throw new ConnectionFailureException('Error connecting to PGSQL database.');
     }
     pg_set_error_verbosity($this->connection, PGSQL_ERRORS_DEFAULT);
     pg_query($this->connection, 'SET standard_conforming_strings=off');
 }
Exemple #11
0
}
</style>
</head>
<body>
<h1>Database content</h1>
<?php 
require 'db_utils.php';
require 'score.php';
$error = FALSE;
$candidate_peer_infos = array();
function q($txt)
{
    return htmlspecialchars($txt, ENT_COMPAT | ENT_HTML401, 'UTF-8');
}
$database = pg_connect("dbname=cadist3d_db user=cadist3d");
pg_set_error_verbosity($database, PGSQL_ERRORS_VERBOSE);
if (!$error) {
    $query = 'SELECT * FROM links;';
    $result = pg_query($database, $query);
    if ($result === FALSE) {
        $error = q(pg_last_error($database));
    } else {
        $links = array();
        $n = pg_num_rows($result);
        for ($i = 0; $i < $n; $i++) {
            $a = pg_fetch_result($result, $i, 'a');
            $b = pg_fetch_result($result, $i, 'b');
            if (!isset($links[$b])) {
                $links[$b] = array();
            }
            if (!isset($links[$a])) {
Exemple #12
0
<?php

// optional functions
include 'config.inc';
$db = pg_connect($conn_str);
$enc = pg_client_encoding($db);
pg_set_client_encoding($db, $enc);
if (function_exists('pg_set_error_verbosity')) {
    pg_set_error_verbosity(PGSQL_ERRORS_TERSE);
    pg_set_error_verbosity(PGSQL_ERRORS_DEFAULT);
    pg_set_error_verbosity(PGSQL_ERRORS_VERBOSE);
}
echo "OK";
Exemple #13
0
	/**
	 * Connection vers le serveur
	 * @param		host		addresse de la base de donnees
	 * @param		login		nom de l'utilisateur autorise
	 * @param		passwd		mot de passe
	 * @param		name		nom de la database (ne sert pas sous mysql, sert sous pgsql)
	 * @param		port		Port of database server
	 * @return		resource	handler d'acces a la base
	 */
	function connect($host, $login, $passwd, $name, $port=0)
	{
		if (!$name){
			$name="postgres";
		}
		if (!$port){
			$port=5432;
		}
		$con_string = "host=$host port=$port dbname=$name user=$login password=$passwd";
        //print 'xxx'.$con_string;
        //$this->db = pg_pconnect($con_string);   // To us persistent connection because this one cost 1ms, non ersisten cost 30ms
        $this->db = pg_connect($con_string);
		if ($this->db)
		{
			$this->database_name = $name;
			pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE);	// Set verbosity to max

		}
		return $this->db;
	}
 function registerUsuario($username, $email, $password, $rol, $foto)
 {
     pg_set_error_verbosity($this->dbConnection, PGSQL_ERRORS_DEFAULT);
     if (!empty($foto)) {
         $result = pg_query($this->dbConnection, "INSERT INTO usuario (pkusu_id,fkusu_rol_id,usu_correo,usu_nombre,usu_clave,usu_imagen)\n\t\t\t\tVALUES(nextval('usuario_pkusu_id_seq'::regclass), '{$rol}', '{$email}', '{$username}', '{$password}', '{$foto}') RETURNING pkusu_id");
     } else {
         $result = pg_query($this->dbConnection, "INSERT INTO usuario (pkusu_id,fkusu_rol_id,usu_correo,usu_nombre,usu_clave,usu_imagen)\n\t\t\t\tVALUES(nextval('usuario_pkusu_id_seq'::regclass), '{$rol}', '{$email}', '{$username}', '{$password}', NULL) RETURNING pkusu_id");
     }
     if (pg_last_error()) {
         return $this->result_construct("error", pg_last_error());
     } else {
         $row = pg_fetch_row($result);
         $id = $row['0'];
         return $this->result_construct("success", $id);
     }
 }
Exemple #15
0
function update_settings($new_settings)
{
    $database = pg_connect("dbname=cadist3d_db user=cadist3d");
    pg_set_error_verbosity($database, PGSQL_ERRORS_VERBOSE);
    $old_settings = get_settings();
    foreach ($new_settings as $new_setting) {
        $found = FALSE;
        foreach ($old_settings as $old_setting) {
            $old_key = $old_setting['key'];
            if ($new_setting['key'] == $old_key) {
                $new_value = $new_setting['value'];
                $found = TRUE;
                if ($new_value != $old_setting['value']) {
                    $query = "UPDATE settings SET value = '{$new_value}'" . " WHERE key = '{$old_key}' ;";
                    $result = pg_query($database, $query);
                }
                break;
            }
        }
    }
}
Exemple #16
0
 /**
  * Connection vers le serveur
  * @param		host		addresse de la base de donnees
  * @param		login		nom de l'utilisateur autorise
  * @param		passwd		mot de passe
  * @param		name		nom de la database (ne sert pas sous mysql, sert sous pgsql)
  * @param		port		Port of database server
  * @return		resource	handler d'acces a la base
  */
 function connect($host, $login, $passwd, $name, $port = 0)
 {
     // use pg_connect() instead of pg_pconnect():
     // To us persistent connection because this one cost 1ms, non persistent cost 30ms
     $this->db = false;
     // connections parameters must be protected (only \ and ' according to pg_connect() manual)
     $host = str_replace(array("\\", "'"), array("\\\\", "\\'"), $host);
     $login = str_replace(array("\\", "'"), array("\\\\", "\\'"), $login);
     $passwd = str_replace(array("\\", "'"), array("\\\\", "\\'"), $passwd);
     $name = str_replace(array("\\", "'"), array("\\\\", "\\'"), $name);
     $port = str_replace(array("\\", "'"), array("\\\\", "\\'"), $port);
     //if (! $name) $name="postgres";
     // try first Unix domain socket (local)
     if (!$host || $host == "" || $host == "localhost") {
         $con_string = "dbname='" . $name . "' user='******' password='******'";
         $this->db = pg_connect($con_string);
     }
     // if local connection failed or not requested, use TCP/IP
     if (!$this->db) {
         if (!$host) {
             $host = "localhost";
         }
         if (!$port) {
             $port = 5432;
         }
         $con_string = "host='" . $host . "' port='" . $port . "' dbname='" . $name . "' user='******' password='******'";
         $this->db = pg_connect($con_string);
     } else {
         $this->database_name = $name;
         pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE);
         // Set verbosity to max
     }
     return $this->db;
 }
 /**
  * Opens a connection to the SQL server
  *
  * Opens a connection to the SQL server, checking for connection errors,
  * and performs a ROLLBACK to make sure any old transaction is cleared.
  *
  * @param bool $force Whether to force a new connection.
  * @return bool true on success, false on error
  * @access public
  */
 public function connect($force = false)
 {
     $constr = '';
     if (empty($this->_socket)) {
         if (!empty($this->_hostname)) {
             $constr .= " host={$this->_hostname}";
         }
         if (!empty($this->_port)) {
             $constr .= " port={$this->_port}";
         }
     }
     if (!empty($this->_username)) {
         $constr .= " user={$this->_username}";
     }
     if (!empty($this->_password)) {
         $constr .= " password={$this->_password}";
     }
     if (!empty($this->_database)) {
         $constr .= " dbname={$this->_database}";
     }
     $force = $force === true ? PGSQL_CONNECT_FORCE_NEW : 0;
     if ($this->_persistent == true) {
         $this->_connection = pg_pconnect($constr, $force);
     } else {
         $this->_connection = pg_connect($constr, $force);
     }
     if ($this->_connection === false) {
         return false;
     }
     if (@pg_query($this->_connection, 'ROLLBACK') === false) {
         return false;
     }
     if (function_exists('pg_set_error_verbosity')) {
         pg_set_error_verbosity($this->_connection, PGSQL_ERRORS_VERBOSE);
     }
     // "If libpq is compiled without multibyte encoding support, pg_client_encoding() always returns SQL_ASCII."
     if (pg_set_client_encoding($this->_connection, 'UNICODE') == -1) {
         return false;
     }
     $this->_log['encoding'] = pg_client_encoding($this->_connection);
     return true;
 }
 public function connect($param)
 {
     $dsn = "host={$param['host']} ";
     $dsn .= isset($param['port']) ? "port={$param['port']} " : '';
     $dsn .= "dbname={$param['dbname']} user={$param['user']} password={$param['pass']}";
     if (!($this->link = @pg_connect($dsn))) {
         throw new XSException('Error connecting to PGSQL database:' . $param['dbname'] . '.');
         pg_set_error_verbosity($this->link, PGSQL_ERRORS_DEFAULT);
         pg_query('SET standard_conforming_strings=off');
     }
 }
 /**
  *	Connexion to server
  *
  *	@param	    string		$host		Database server host
  *	@param	    string		$login		Login
  *	@param	    string		$passwd		Password
  *	@param		string		$name		Name of database (not used for mysql, used for pgsql)
  *	@param		string		$port		Port of database server
  *	@return		resource				Database access handler
  *	@see		close
  */
 function connect($host, $login, $passwd, $name, $port = 0)
 {
     // use pg_pconnect() instead of pg_connect() if you want to use persistent connection costing 1ms, instead of 30ms for non persistent
     $this->db = false;
     // connections parameters must be protected (only \ and ' according to pg_connect() manual)
     $host = str_replace(array("\\", "'"), array("\\\\", "\\'"), $host);
     $login = str_replace(array("\\", "'"), array("\\\\", "\\'"), $login);
     $passwd = str_replace(array("\\", "'"), array("\\\\", "\\'"), $passwd);
     $name = str_replace(array("\\", "'"), array("\\\\", "\\'"), $name);
     $port = str_replace(array("\\", "'"), array("\\\\", "\\'"), $port);
     if (!$name) {
         $name = "postgres";
     }
     // When try to connect using admin user
     // try first Unix domain socket (local)
     if (!empty($host) && $host == "socket" && !defined('NOLOCALSOCKETPGCONNECT')) {
         $con_string = "dbname='" . $name . "' user='******' password='******'";
         // $name may be empty
         $this->db = @pg_connect($con_string);
     }
     // if local connection failed or not requested, use TCP/IP
     if (!$this->db) {
         if (!$host) {
             $host = "localhost";
         }
         if (!$port) {
             $port = 5432;
         }
         $con_string = "host='" . $host . "' port='" . $port . "' dbname='" . $name . "' user='******' password='******'";
         $this->db = @pg_connect($con_string);
     }
     // now we test if at least one connect method was a success
     if ($this->db) {
         $this->database_name = $name;
         pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE);
         // Set verbosity to max
     }
     return $this->db;
 }
Exemple #20
0
 /**
  * Connects to the database if needed.
  *
  * @return  void  Returns void if the database connected successfully.
  *
  * @since   12.1
  * @throws  RuntimeException
  */
 public function connect()
 {
     if ($this->connection) {
         return;
     }
     // Make sure the postgresql extension for PHP is installed and enabled.
     if (!function_exists('pg_connect')) {
         throw new RuntimeException('PHP extension pg_connect is not available.');
     }
     // Build the DSN for the connection.
     $dsn = '';
     if (!empty($this->options['host'])) {
         $dsn .= "host={$this->options['host']} ";
     }
     $dsn .= "dbname={$this->options['database']} user={$this->options['user']} password={$this->options['password']}";
     // Attempt to connect to the server.
     if (!($this->connection = @pg_connect($dsn))) {
         throw new RuntimeException('Error connecting to PGSQL database.');
     }
     pg_set_error_verbosity($this->connection, PGSQL_ERRORS_DEFAULT);
     pg_query('SET standard_conforming_strings=off');
     pg_query('SET escape_string_warning=off');
 }
 /**
  * Create a PostgreSQL Server Custom Connection.
  * This MUST NOT be used with the default connection ... as that is handled automatically.
  *
  * @param STRING $yhost 						:: db host
  * @param STRING $yport 						:: db port
  * @param STRING $ydb 							:: db name
  * @param STRING $yuser							:: db user
  * @param STRING $ypass							:: db pass
  * @param INTEGER $ytimeout 					:: connection timeout
  * @param ENUM $y_transact_mode					:: transactional mode ('READ COMMITTED' | 'REPEATABLE READ' | 'SERIALIZABLE' | '' to leave it as default)
  * @param FLOAT $y_debug_sql_slowtime			:: debug query slow time
  * @param ENUM $y_type							:: server type: postgresql or pgpool2
  *
  * @return RESOURCE								:: the postgresql connection resource ID
  *
  * @access 		private
  * @internal
  *
  */
 public static function server_connect($yhost, $yport, $ydb, $yuser, $ypass, $ytimeout, $y_transact_mode = '', $y_debug_sql_slowtime = 0, $y_type = 'postgresql')
 {
     //--
     if (defined('SMART_FRAMEWORK_DBSQL_CHARSET')) {
         if ((string) SMART_FRAMEWORK_DBSQL_CHARSET != 'UTF8') {
             die('The SMART_FRAMEWORK_DBSQL_CHARSET must be set as: UTF8');
         }
         //end if
     } else {
         die('The SMART_FRAMEWORK_DBSQL_CHARSET must be set ...');
     }
     //end if else
     //--
     //--
     if (!function_exists('pg_connect')) {
         self::error('[PRE-CONNECT]', 'PHP-PgSQL', 'Check PgSQL PHP Extension', 'PHP Extension is required to run this software !', 'Cannot find PgSQL PHP Extension');
         return;
     }
     //end if
     //--
     if ((string) ini_get('pgsql.ignore_notice') != '0') {
         // {{{SYNC-PGSQL-NOTIF-CHECK}}}
         self::error('[PRE-CONNECT]', 'PHP-Inits-PgSQL', 'Check PgSQL PHP.INI Settings', 'SETTINGS: PostgreSQL Notifications need to be ENABLED in PHP.INI !', 'SET in PHP.INI this: pgsql.ignore_notice = 0');
         return;
     }
     //end if
     //--
     //-- connection timeout
     $timeout = (int) $ytimeout;
     //--
     if ($timeout < 1) {
         $timeout = 1;
     }
     //end if
     if ($timeout > 60) {
         $timeout = 60;
     }
     //end if
     //--
     //-- debug settings
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         $y_debug_sql_slowtime = (double) $y_debug_sql_slowtime;
         if ($y_debug_sql_slowtime <= 0) {
             $y_debug_sql_slowtime = (double) self::$slow_time;
         }
         //end if
         //--
         if ($y_debug_sql_slowtime < 1.0E-7) {
             $y_debug_sql_slowtime = 1.0E-7;
         } elseif ($y_debug_sql_slowtime > 0.9999999000000001) {
             $y_debug_sql_slowtime = 0.9999999000000001;
         }
         //end if
         //--
         self::$slow_time = (double) $y_debug_sql_slowtime;
         // update
         //--
     }
     //end if
     //--
     //-- debug inits
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|slow-time', number_format(self::$slow_time, 7, '.', ''), '=');
         SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|log', ['type' => 'metainfo', 'data' => 'Database Server: PgSQL (' . $y_type . ') / App Connector Version: ' . SMART_FRAMEWORK_VERSION . ' / Connection Charset: ' . SMART_FRAMEWORK_DBSQL_CHARSET]);
         SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|log', ['type' => 'metainfo', 'data' => 'Connection Timeout: ' . $timeout . ' seconds / Fast Query Reference Time < ' . self::$slow_time . ' seconds']);
     }
     //end if
     //--
     //--
     if ((string) $ypass != '') {
         $password = (string) base64_decode((string) $ypass);
     } else {
         $password = '';
     }
     //end if else
     //--
     //-- {{{SYNC-CONNECTIONS-IDS}}}
     $the_conn_key = (string) $yhost . ':' . $yport . '@' . $ydb . '#' . $yuser . '>' . trim(strtoupper(str_replace(' ', '', (string) $y_transact_mode))) . '.';
     //--
     $connection = @pg_connect('host=' . $yhost . ' port=' . $yport . ' dbname=' . $ydb . ' user='******' password='******' connect_timeout=' . $timeout);
     // @pg_close($connection) (if is resource) ; but reusing connections policy dissalow disconnects
     //--
     if (!is_resource($connection)) {
         self::error($yhost . ':' . $yport . '@' . $ydb . '#' . $yuser, 'Connection', 'Connect to PgSQL Server', 'NO CONNECTION !!!', 'Connection Failed to PgSQL Server !');
         return;
     }
     //end if
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|log', ['type' => 'open-close', 'data' => 'Connected to PgSQL Server: ' . $the_conn_key, 'connection' => (string) $connection]);
     }
     //end if
     //--
     //--
     @pg_set_error_verbosity($connection, PGSQL_ERRORS_DEFAULT);
     // this must be reset to PGSQL_ERRORS_DEFAULT and must NOT use PGSQL_ERRORS_VERBOSE because will affect write-igdata notice messages
     //--
     $tmp_pg_tracefile = 'tmp/logs/pgsql-trace.log';
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         if (defined('SMART_FRAMEWORK_DEBUG_SQL_TRACE')) {
             if (function_exists('pg_trace')) {
                 @pg_trace($tmp_pg_tracefile, 'w', $connection);
                 // pg_trace can cause some PHP versions to crash (Ex: Debian 6.0.6 with PHP 5.3 / Apache 2.0.x)
             }
             //end if
         }
         //end if
         //--
     }
     //end if else
     //--
     //--
     $result = @pg_query_params($connection, 'SELECT pg_encoding_to_char("encoding") FROM "pg_database" WHERE "datname" = $1', array($ydb));
     if (!$result) {
         self::error($connection, 'Encoding-Charset', 'Check Query Failed', 'Error=' . @pg_last_error($connection), 'DB=' . $ydb);
         return;
     }
     //end if
     $server_encoding = @pg_fetch_row($result);
     if (trim($server_encoding[0]) != trim(SMART_FRAMEWORK_DBSQL_CHARSET)) {
         self::error($connection, 'Encoding-Get-Charset', 'Wrong Server Encoding on PgSQL Server', 'Server=' . $server_encoding[0], 'Client=' . SMART_FRAMEWORK_DBSQL_CHARSET);
         return;
     }
     //end if
     @pg_free_result($result);
     //--
     //--
     $encoding = @pg_set_client_encoding($connection, SMART_FRAMEWORK_DBSQL_CHARSET);
     //--
     if ($encoding < 0 or (string) @pg_client_encoding() != (string) SMART_FRAMEWORK_DBSQL_CHARSET) {
         self::error($connection, 'Encoding-Check-Charset', 'Failed to set Client Encoding on PgSQL Server', 'Server=' . SMART_FRAMEWORK_DBSQL_CHARSET, 'Client=' . @pg_client_encoding());
         return;
     }
     //end if
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|log', ['type' => 'set', 'data' => 'SET Client Encoding [+check] to: ' . @pg_client_encoding(), 'connection' => (string) $connection, 'skip-count' => 'yes']);
     }
     //end if
     //--
     //--
     $transact = strtoupper((string) $y_transact_mode);
     switch ((string) $transact) {
         case 'SERIALIZABLE':
         case 'REPEATABLE READ':
         case 'READ COMMITTED':
             //--
             $result = @pg_query($connection, 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $transact);
             if (!$result) {
                 self::error($connection, 'Set-Session-Transaction-Level', 'Failed to Set Session Transaction Level as ' . $transact, 'Error=' . @pg_last_error($connection), 'DB=' . $ydb);
                 return;
             }
             //end if
             @pg_free_result($result);
             //--
             $result = @pg_query('SHOW transaction_isolation');
             $chk = @pg_fetch_row($result);
             if ((string) trim($chk[0]) == '' or (string) $transact != (string) strtoupper(trim($chk[0]))) {
                 self::error($connection, 'Check-Session-Transaction-Level', 'Failed to Set Session Transaction Level as ' . $transact, 'Error=' . @pg_last_error($connection), 'DB=' . $ydb);
                 return;
             }
             //end if
             if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                 SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|log', ['type' => 'set', 'data' => 'SET Session Transaction Isolation Level [+check] to: ' . strtoupper($chk[0]), 'connection' => (string) $connection, 'skip-count' => 'yes']);
             }
             //end if
             @pg_free_result($result);
             //--
             break;
         default:
             // LEAVE THE SESSION TRANSACTION AS SET IN CFG
     }
     //end switch
     //--
     //-- export only at the end (after all settings)
     SmartFrameworkRegistry::$Connections['pgsql'][(string) $the_conn_key] = $connection;
     // export connection
     //--
     //-- OUTPUT
     return $connection;
     //-- OUTPUT
 }