summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorMark Weiman <mark.weiman@markzz.com>2016-11-10 00:54:38 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2016-11-10 18:31:20 +0100
commit6502518d4e190b92ce771389d437a001687950d0 (patch)
tree80c9e2933e85043a27599bb95b4a4146855c0eec /web
parent3e442a0f7d49fc8eed45002841d84d9080473cc9 (diff)
downloadaur-6502518d4e190b92ce771389d437a001687950d0.tar.gz
aur-6502518d4e190b92ce771389d437a001687950d0.tar.xz
Fix DB.class.php to match config and include SQLite support
In commit baf8a22 (git-interface: Support SQLite as database backend, 2016-08-03), conf/config.proto was changed so that dsn_prefix was changed to backend and this fixes this in web/lib/DB.class.php. Since SQLite's dsn is different, this adds a check of which backend is desired and will quit if MySQL or SQLite are not the backend selected. SQLite2 may be supported, but is untested and will trigger an error if used. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web')
-rw-r--r--web/lib/DB.class.php24
1 files changed, 17 insertions, 7 deletions
diff --git a/web/lib/DB.class.php b/web/lib/DB.class.php
index b538e0d3..dfdbbf96 100644
--- a/web/lib/DB.class.php
+++ b/web/lib/DB.class.php
@@ -17,20 +17,30 @@ class DB {
public static function connect() {
if (self::$dbh === null) {
try {
- $dsn_prefix = config_get('database', 'dsn_prefix');
+ $backend = config_get('database', 'backend');
$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;
+ if ($backend == "mysql") {
+ $dsn = $backend .
+ ':host=' . $host .
+ ';unix_socket=' . $socket .
+ ';dbname=' . $name;
+
+ self::$dbh = new PDO($dsn, $user, $password);
+ self::$dbh->exec("SET NAMES 'utf8' COLLATE 'utf8_general_ci';");
+ } else if ($backend == "sqlite") {
+ $dsn = $backend .
+ ":" . $name;
+
+ self::$dbh = new PDO($dsn, null, null);
+ } else {
+ die("Error - " . $backend . " is not supported by aurweb");
+ }
- 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');
}