diff --git a/functions.inc.php b/functions.inc.php index aa5e31c1..7ef0ff50 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1464,29 +1464,14 @@ EOF; * @return \PDO */ function db_connect() { - list($link, $error_text) = db_connect_with_errors(); - - if (!$link instanceof PDO) { - throw new Exception("Database connection failed: $error_text"); - } - - return $link; -} - -/** - * @param bool $ignore_errors - * @return array [PDO link | false, string $error_text]; - */ -function db_connect_with_errors() { global $CONF; - global $DEBUG_TEXT; - - $error_text = ''; + /* some attempt at not reopening an existing connection */ static $link; if (isset($link) && $link) { - return array($link, $error_text); + return $link; } + $link = false; $options = array( @@ -1520,17 +1505,17 @@ function db_connect_with_errors() { if (!file_exists($db)) { $error_text = 'SQLite database missing: '. $db; - return array($link, $error_text); + throw new Exception($error_text); } if (!is_writeable($db)) { $error_text = 'SQLite database not writeable: '. $db; - return array($link, $error_text); + throw new Exception($error_text); } if (!is_writeable(dirname($db))) { $error_text = 'The directory the SQLite database is in is not writeable: '. dirname($db); - return array($link, $error_text); + throw new Exception($error_text); } $dsn = "sqlite:{$db}"; @@ -1556,7 +1541,8 @@ function db_connect_with_errors() { } } - return array($link, $error_text); + return $link; + } /** diff --git a/public/setup.php b/public/setup.php index d824e782..f044b775 100644 --- a/public/setup.php +++ b/public/setup.php @@ -184,7 +184,15 @@ if ($f_sqlite_open == 1) { // // Database connection // -list($link, $error_text) = db_connect_with_errors(); +$link = null; +$error_text = null; + +try { + $link = db_connect(); +} +catch(Exception $e) { + $error_text = $e->getMessage(); +} if (!empty($link) && $error_text == "") { print "