function __construct($parameters) { parent::__construct($parameters); if (!extension_loaded('pgsql')) { if (function_exists('eZAppendWarningItem')) { eZAppendWarningItem(array('error' => array('type' => 'ezdb', 'number' => eZDBInterface::ERROR_MISSING_EXTENSION), 'text' => 'PostgreSQL extension was not found, the DB handler will not be initialized.')); $this->IsConnected = false; } eZDebug::writeWarning('PostgreSQL extension was not found, the DB handler will not be initialized.', 'eZPostgreSQLDB'); return; } eZDebug::createAccumulatorGroup('postgresql_total', 'Postgresql Total'); $ini = eZINI::instance(); $server = $this->Server; $port = $this->Port; $db = $this->DB; $user = $this->User; $password = $this->Password; $connectString = self::connectString($this->Server, $this->Port, $this->DB, $this->User, $this->Password); if ($ini->variable("DatabaseSettings", "UsePersistentConnection") == "enabled" && function_exists("pg_pconnect")) { eZDebugSetting::writeDebug('kernel-db-postgresql', $ini->variable("DatabaseSettings", "UsePersistentConnection"), "using persistent connection"); // avoid automatic SQL errors $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_pconnect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $maxAttempts = $this->connectRetryCount(); $waitTime = $this->connectRetryWaitTime(); $numAttempts = 1; while ($this->DBConnection == false and $numAttempts <= $maxAttempts) { sleep($waitTime); $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_pconnect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $numAttempts++; } if ($this->DBConnection) { $this->IsConnected = true; } else { throw new eZDBNoConnectionException($server, $this->ErrorMessage, $this->ErrorNumber); } } else { if (function_exists("pg_connect")) { eZDebugSetting::writeDebug('kernel-db-postgresql', "using real connection", "using real connection"); $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_connect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $maxAttempts = $this->connectRetryCount(); $waitTime = $this->connectRetryWaitTime(); $numAttempts = 1; while ($this->DBConnection == false and $numAttempts <= $maxAttempts) { sleep($waitTime); $oldHandling = eZDebug::setHandleType(eZDebug::HANDLE_EXCEPTION); eZDebug::accumulatorStart('postgresql_connection', 'postgresql_total', 'Database connection'); try { $this->DBConnection = pg_connect($connectString); } catch (ErrorException $e) { } eZDebug::accumulatorStop('postgresql_connection'); eZDebug::setHandleType($oldHandling); $numAttempts++; } if ($this->DBConnection) { $this->IsConnected = true; } else { $this->setError(); throw new eZDBNoConnectionException($server, $this->ErrorMessage, $this->ErrorNumber); } } else { $this->IsConnected = false; eZDebug::writeError("PostgreSQL support not compiled into PHP, contact your system administrator", "eZPostgreSQLDB"); } } }
function __construct($parameters) { parent::__construct($parameters); }