Ejemplo n.º 1
0
 /**
  * Class Constructor
  * It will initiate also the custom connection
  * or will re-use an existing connection (if the same connection parameters are provided)
  * for a PostgreSQL Server.
  *
  * @param ARRAY $y_configs_arr 					:: The Array of Configuration parameters for the connection - the ARRAY STRUCTURE should be identical with the default config.php: $configs['pgsql'].
  *
  */
 public function __construct($y_configs_arr)
 {
     //--
     $y_configs_arr = (array) $y_configs_arr;
     //-- {{{SYNC-CONNECTIONS-IDS}}}
     $the_conn_key = (string) $y_configs_arr['server-host'] . ':' . $y_configs_arr['server-port'] . '@' . $y_configs_arr['dbname'] . '#' . $y_configs_arr['username'] . '>' . trim(strtoupper(str_replace(' ', '', (string) $y_configs_arr['transact']))) . '.';
     if (array_key_exists((string) $the_conn_key, (array) SmartFrameworkRegistry::$Connections['pgsql'])) {
         //-- try to reuse the connection :: only check if array key exists, not if it is a valid resource ; this should be as so to avoid mismatching connection mixings (if by example will re-use the connection of another server, and connection is broken in the middle of a transaction, it will fail ugly ;) and out of any control !
         $this->connection = SmartFrameworkRegistry::$Connections['pgsql'][(string) $the_conn_key];
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             SmartFrameworkRegistry::setDebugMsg('db', 'pgsql|log', ['type' => 'open-close', 'data' => 'Re-Using Connection to PgSQL Server: ' . $the_conn_key, 'connection' => (string) $this->connection]);
         }
         //end if
         //--
     } else {
         //-- connect
         $this->connection = SmartPgsqlDb::server_connect((string) $y_configs_arr['server-host'], (int) $y_configs_arr['server-port'], (string) $y_configs_arr['dbname'], (string) $y_configs_arr['username'], (string) $y_configs_arr['password'], (int) $y_configs_arr['timeout'], (string) $y_configs_arr['transact'], (double) $y_configs_arr['slowtime'], (string) $y_configs_arr['type']);
         //--
         $this->check_server_version(true);
         // re-validate
         //--
     }
     //end if else
     //--
 }