Skip to content

Commit

Permalink
database checks in init.php
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanRichter committed Jul 9, 2015
1 parent 8b70620 commit fc12bf3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@
}
// Start database connection
// Depending on the DB driver, instantiate a PDO object with the necessary credentials.
$db_drivers = PDO::getAvailableDrivers();
if (!in_array($db_driver,$db_drivers)){
die('Requested to use '.$db_driver.', which is not enabled!');
}
switch ($db_driver) {
case "mysql":
if (!empty($db_name) and !empty($db_user)) {
$conn = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", $db_user, $db_pass);
break;
}
if (empty($db_name) or empty($db_user)){
die('You must set $db_name and $db_user in /config/'.CL_CONFIG . '/config.php to use mysql, or set $db_driver to "sqlite" to use an SQLite database!');
}
$conn = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", $db_user, $db_pass);
break;
case "sqlite":
$conn = new PDO("sqlite:" . CL_ROOT . "/files/collabtive.sdb");
break;
Expand Down

0 comments on commit fc12bf3

Please sign in to comment.