diff --git a/db/config.php b/db/config.php index d79508d..0560579 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,32 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; -} +function db() +{ + static $p = null; + if ($p) { + return $p; + } + + // Try common Flatlogic defaults + $host = '127.0.0.1'; + $port = 3306; + $dbname = 'verified_donations'; // Keep this as-is + $username = 'root'; // Most common default user + $password = ''; // Often no password + + $dsn = "mysql:host=$host;port=$port;dbname=$dbname;charset=utf8mb4"; + + try { + $p = new PDO($dsn, $username, $password, [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]); + return $p; + } catch (PDOException $e) { + // Friendly error message for users + error_log('Database connection failed: ' . $e->getMessage()); + throw new Exception("Database not ready. Please contact support."); + } +} \ No newline at end of file