mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-24 20:13:22 +01:00
[ticket/10057] Report postgres db connection errors.
Addresses two issues: 1. When pgsql extension is missing, @pg_connect would silently abort execution. Check for pg_connect existence before calling it, same with pg_pconnect. 2. When connection fails, the error reported by php is discarded. User is shown the failure message without the reason for failure, making debugging difficult. Collect the error (if any) via a temporarily installed error handler, and display it if connection failed. PHPBB3-10057
This commit is contained in:
parent
f08cbc73de
commit
d69a7c620a
@ -81,13 +81,25 @@ class dbal_postgres extends dbal
|
||||
|
||||
if ($this->persistency)
|
||||
{
|
||||
if (!function_exists('pg_pconnect'))
|
||||
{
|
||||
return $this->sql_error('pg_pconnect does not exist');
|
||||
}
|
||||
phpbb_start_error_collection();
|
||||
$this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!function_exists('pg_pconnect'))
|
||||
{
|
||||
return $this->sql_error('pg_connect does not exist');
|
||||
}
|
||||
phpbb_start_error_collection();
|
||||
$this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);
|
||||
}
|
||||
|
||||
$errors = phpbb_stop_error_collection();
|
||||
|
||||
if ($this->db_connect_id)
|
||||
{
|
||||
if (version_compare($this->sql_server_info(true), '8.2', '>='))
|
||||
@ -102,7 +114,8 @@ class dbal_postgres extends dbal
|
||||
return $this->db_connect_id;
|
||||
}
|
||||
|
||||
return $this->sql_error('');
|
||||
$errors = phpbb_format_collected_errors($errors);
|
||||
return $this->sql_error($errors);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3928,6 +3928,50 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
|
||||
return false;
|
||||
}
|
||||
|
||||
function phpbb_error_collection_handler($errno, $msg_text, $errfile, $errline)
|
||||
{
|
||||
global $phpbb_collected_errors;
|
||||
$phpbb_collected_errors[-1][] = array($errno, $msg_text, $errfile, $errline);
|
||||
}
|
||||
|
||||
function phpbb_start_error_collection()
|
||||
{
|
||||
global $phpbb_collected_errors;
|
||||
if (!isset($phpbb_collected_errors))
|
||||
{
|
||||
$phpbb_collected_errors = array();
|
||||
}
|
||||
$phpbb_collected_errors[] = array();
|
||||
set_error_handler('phpbb_error_collection_handler');
|
||||
}
|
||||
|
||||
function phpbb_stop_error_collection()
|
||||
{
|
||||
global $phpbb_collected_errors;
|
||||
restore_error_handler();
|
||||
$errors = array_pop($phpbb_collected_errors);
|
||||
return $errors;
|
||||
}
|
||||
|
||||
function phpbb_format_collected_errors($errors)
|
||||
{
|
||||
$text = '';
|
||||
foreach ($errors as $error)
|
||||
{
|
||||
if (!empty($text))
|
||||
{
|
||||
$text .= "<br />\n";
|
||||
}
|
||||
list($errno, $msg_text, $errfile, $errline) = $error;
|
||||
$text .= "Errno $errno: $msg_text";
|
||||
if (defined('DEBUG'))
|
||||
{
|
||||
$text .= " at $errfile line $errline";
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the session table to get information about online guests
|
||||
* @param int $item_id Limits the search to the item with this id
|
||||
|
Loading…
x
Reference in New Issue
Block a user