1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-09 23:56:58 +02:00

PostgreDriver: removed usage of tryError & catchError

This commit is contained in:
David Grudl
2015-10-13 20:02:00 +02:00
parent 1a027c75ab
commit 8649366b1f

View File

@@ -57,6 +57,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
*/ */
public function connect(array & $config) public function connect(array & $config)
{ {
$error = NULL;
if (isset($config['resource'])) { if (isset($config['resource'])) {
$this->connection = $config['resource']; $this->connection = $config['resource'];
@@ -77,27 +78,25 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
} }
} }
Dibi\DriverException::tryError(); set_error_handler(function($severity, $message) use (& $error) {
$error = $message;
});
if (empty($config['persistent'])) { if (empty($config['persistent'])) {
$this->connection = pg_connect($string, PGSQL_CONNECT_FORCE_NEW); $this->connection = pg_connect($string, PGSQL_CONNECT_FORCE_NEW);
} else { } else {
$this->connection = pg_pconnect($string, PGSQL_CONNECT_FORCE_NEW); $this->connection = pg_pconnect($string, PGSQL_CONNECT_FORCE_NEW);
} }
if (Dibi\DriverException::catchError($msg)) { restore_error_handler();
throw new Dibi\DriverException($msg, 0);
}
} }
if (!is_resource($this->connection)) { if (!is_resource($this->connection)) {
throw new Dibi\DriverException('Connecting error.'); throw new Dibi\DriverException($error ?: 'Connecting error.');
} }
if (isset($config['charset'])) { pg_set_error_verbosity($this->connection, PGSQL_ERRORS_VERBOSE);
Dibi\DriverException::tryError();
pg_set_client_encoding($this->connection, $config['charset']); if (isset($config['charset']) && pg_set_client_encoding($this->connection, $config['charset'])) {
if (Dibi\DriverException::catchError($msg)) { throw new Dibi\DriverException(pg_last_error($this->connection), 0, $sql);
throw new Dibi\DriverException($msg, 0);
}
} }
if (isset($config['schema'])) { if (isset($config['schema'])) {