aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2011-02-23 20:12:12 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2011-03-06 20:16:16 -0500
commitd69a7c620a08d1866a24033ef43646a4bbfc9925 (patch)
tree04e1dfac1a0a9be42c61bebb85c9c83a073d66ec /phpBB/includes/functions.php
parentf08cbc73de208dab29737ab53db3af8a6a2d97fc (diff)
downloadforums-d69a7c620a08d1866a24033ef43646a4bbfc9925.tar
forums-d69a7c620a08d1866a24033ef43646a4bbfc9925.tar.gz
forums-d69a7c620a08d1866a24033ef43646a4bbfc9925.tar.bz2
forums-d69a7c620a08d1866a24033ef43646a4bbfc9925.tar.xz
forums-d69a7c620a08d1866a24033ef43646a4bbfc9925.zip
[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
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 398a02380b..471d3476a0 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -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