| try { | |
| // Create (or connect to) the SQLite database in the same directory | |
| $db = new PDO('sqlite:' . __DIR__ . '/database.sqlite'); | |
| // Set error mode to exceptions | |
| $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
| // Fetch results as associative arrays by default | |
| $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); | |
| } catch (PDOException $e) { | |
| die("Database connection failed: " . $e->getMessage()); | |
| } | |