PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } return $pdo; } function apply_schema() { $pdo = db(); $schema = file_get_contents(__DIR__ . '/schema.sql'); if ($schema === false) { throw new Exception("Could not read schema.sql"); } $pdo->exec($schema); } // Automatically apply schema on inclusion. // In a real app, you'd use a more robust migration system. try { apply_schema(); } catch (Exception $e) { // You might want to log this error instead of echoing it error_log("Schema application failed: " . $e->getMessage()); // Optionally, you could re-throw or handle it to prevent app execution }