diff --git a/db/config.php b/db/config.php index 0560579..8df4656 100644 --- a/db/config.php +++ b/db/config.php @@ -1,32 +1,29 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - PDO::ATTR_EMULATE_PREPARES => false, - ]); - return $p; + $pdo = new PDO("sqlite:$dbFile"); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); + + // Enable foreign keys & UTF-8 + $pdo->exec("PRAGMA foreign_keys = ON;"); + $pdo->exec("PRAGMA encoding = 'UTF-8';"); + + return $pdo; } catch (PDOException $e) { - // Friendly error message for users - error_log('Database connection failed: ' . $e->getMessage()); - throw new Exception("Database not ready. Please contact support."); + throw new Exception("SQLite error: " . $e->getMessage()); } } \ No newline at end of file