1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-24 20:13:22 +01:00

[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
This commit is contained in:
Oleg Pudeyev 2011-03-06 23:17:01 -05:00
parent edc1deaa3a
commit 98388b2921

View File

@ -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' => ''
);
}