35562-vm/db/config.php

32 lines
935 B
PHP

<?php
// db/config.php - FIXED FOR FLATLOGIC DEFAULT DB
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.");
}
}