You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
678 B
28 lines
678 B
<?php
|
|
|
|
/**
|
|
* @return PDO The PDO instance of the configuration's database connection.
|
|
*/
|
|
function get_database(): PDO {
|
|
// defined by profiles.
|
|
global $data_source_name;
|
|
$pdo = new PDO($data_source_name, DATABASE_USER, DATABASE_PASSWORD, [PDO::ERRMODE_EXCEPTION]);
|
|
|
|
$database_exists = $pdo->query("SELECT COUNT(*) FROM sqlite_master WHERE type = 'table'")->fetchColumn() > 0;
|
|
|
|
if ($database_exists) {
|
|
return $pdo;
|
|
}
|
|
|
|
foreach (scandir(__DIR__) as $file) {
|
|
if (preg_match("/.*\.sql$/i", $file)) {
|
|
$content = file_get_contents(__DIR__ . "/" . $file);
|
|
|
|
$pdo->exec($content);
|
|
}
|
|
}
|
|
|
|
|
|
return $pdo;
|
|
}
|