From 98388b29212cf94c443e0b4f626508efc937715f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 6 Mar 2011 23:17:01 -0500 Subject: [ticket/10057] Fixed wrong usage of sql_error in postgres dbal. pg_last_error does not work if no connection was ever established. Therefore we must keep track of connection errors in postgres dbal ourselves. PHPBB3-10057 --- phpBB/includes/db/postgres.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/db/postgres.php') diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index d703f5b567..78b6a75750 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -31,6 +31,7 @@ if (!class_exists('phpbb_error_collector')) class dbal_postgres extends dbal { var $last_query_text = ''; + var $connect_error = ''; /** * Connect to server @@ -121,8 +122,8 @@ class dbal_postgres extends dbal return $this->db_connect_id; } - $errors = $collector->format_errors(); - return $this->sql_error($errors); + $this->connect_error = $collector->format_errors(); + return $this->sql_error(''); } /** @@ -391,8 +392,19 @@ class dbal_postgres extends dbal */ function _sql_error() { + // pg_last_error only works when there is an established connection. + // Connection errors have to be tracked by us manually. + if ($this->db_connect_id) + { + $message = @pg_last_error($this->db_connect_id); + } + else + { + $message = $this->connect_error; + } + return array( - 'message' => (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id), + 'message' => $message, 'code' => '' ); } -- cgit v1.2.1