From a36e46d44db24622eeed4438342dfdbd98a28727 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 21 Jan 2012 22:00:33 +0100 Subject: Setup script and clean config file. --- ratatoeskr/sys/db.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'ratatoeskr/sys/db.php') diff --git a/ratatoeskr/sys/db.php b/ratatoeskr/sys/db.php index 6add093..5ab2688 100644 --- a/ratatoeskr/sys/db.php +++ b/ratatoeskr/sys/db.php @@ -10,7 +10,9 @@ * See "ratatoeskr/licenses/ratatoeskr" for more information. */ -require_once(dirname(__FILE__) . "/../config.php"); +if(!defined("SETUP")) + require_once(dirname(__FILE__) . "/../config.php"); + require_once(dirname(__FILE__) . "/utils.php"); /* @@ -21,16 +23,16 @@ require_once(dirname(__FILE__) . "/utils.php"); function db_connect() { global $config; - $db_connection = mysql_pconnect( + $db_connection = @mysql_pconnect( $config["mysql"]["server"], $config["mysql"]["user"], $config["mysql"]["passwd"]); if(!$db_connection) - die("Could not connect to database server. " . mysql_error()); + throw new MySQLException("Could not connect to database server. " . mysql_error()); + + if(!@mysql_select_db($config["mysql"]["db"], $db_connection)) + throw new MySQLException("Could not open database. " . mysql_error()); - if(!mysql_select_db($config["mysql"]["db"], $db_connection)) - die("Could not open database. " . mysql_error()); - mysql_query("SET NAMES 'utf8'", $db_connection); } -- cgit v1.2.3-54-g00ecf