Initial commit: sync from server - all domains and code
This commit is contained in:
37
www/fahrschultermin.de/app/Support/Database.php
Normal file
37
www/fahrschultermin.de/app/Support/Database.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use PDO;
|
||||
|
||||
final class Database
|
||||
{
|
||||
private static string $path;
|
||||
private static ?PDO $connection = null;
|
||||
|
||||
public static function configure(string $path): void
|
||||
{
|
||||
self::$path = $path;
|
||||
}
|
||||
|
||||
public static function connection(): PDO
|
||||
{
|
||||
if (self::$connection instanceof PDO) {
|
||||
return self::$connection;
|
||||
}
|
||||
|
||||
$directory = dirname(self::$path);
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0775, true);
|
||||
}
|
||||
|
||||
self::$connection = new PDO('sqlite:' . self::$path);
|
||||
self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
self::$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
self::$connection->exec('PRAGMA foreign_keys = ON');
|
||||
|
||||
return self::$connection;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user