Edit db/config.php via Editor
This commit is contained in:
parent
3aeab0df74
commit
489adf71dd
@ -1,32 +1,29 @@
|
||||
<?php
|
||||
// db/config.php - FIXED FOR FLATLOGIC DEFAULT DB
|
||||
// db/config.php — USING SQLITE (no DB server needed)
|
||||
|
||||
function db()
|
||||
{
|
||||
static $p = null;
|
||||
if ($p) {
|
||||
return $p;
|
||||
static $pdo = null;
|
||||
if ($pdo) return $pdo;
|
||||
|
||||
$dbFile = __DIR__ . '/../database.sqlite';
|
||||
|
||||
// Ensure db directory exists
|
||||
if (!is_dir(dirname($dbFile))) {
|
||||
mkdir(dirname($dbFile), 0755, true);
|
||||
}
|
||||
|
||||
// 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;
|
||||
$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());
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user