diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2014-10-24 08:31:47 +0200 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2014-10-24 10:03:54 +0200 |
commit | 76343fb91511b9f53e58b6c01b258bfe00ddb4c6 (patch) | |
tree | 60eb4d3727bae159a1807915a58348b210ead206 /web/lib/DB.class.php | |
parent | a0a523070847230565c2ad5993ee058ff475a8e1 (diff) | |
download | aur-76343fb91511b9f53e58b6c01b258bfe00ddb4c6.tar.gz aur-76343fb91511b9f53e58b6c01b258bfe00ddb4c6.tar.xz |
Use an INI-style configuration file
Replace web/lib/config.inc.php with an INI-style configuration file.
This allows us to get rid of several globals and makes it easier to use
the same configuration file in external scripts.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib/DB.class.php')
-rw-r--r-- | web/lib/DB.class.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/web/lib/DB.class.php b/web/lib/DB.class.php index 09759892..b538e0d3 100644 --- a/web/lib/DB.class.php +++ b/web/lib/DB.class.php @@ -1,5 +1,7 @@ <?php +include_once("confparser.inc.php"); + class DB { /** @@ -15,8 +17,19 @@ class DB { public static function connect() { if (self::$dbh === null) { try { - self::$dbh = new PDO(AUR_db_DSN_prefix . ":" . AUR_db_host - . ";dbname=" . AUR_db_name, AUR_db_user, AUR_db_pass); + $dsn_prefix = config_get('database', 'dsn_prefix'); + $host = config_get('database', 'host'); + $socket = config_get('database', 'socket'); + $name = config_get('database', 'name'); + $user = config_get('database', 'user'); + $password = config_get('database', 'password'); + + $dsn = $dsn_prefix . + ':host=' . $host . + ';unix_socket=' . $socket . + ';dbname=' . $name; + + self::$dbh = new PDO($dsn, $user, $password); self::$dbh->exec("SET NAMES 'utf8' COLLATE 'utf8_general_ci';"); } catch (PDOException $e) { die('Error - Could not connect to AUR database'); |