PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); // Auto-install check: if 'settings' table doesn't exist, run install.sql static $checked = false; if (!$checked) { $checked = true; $res = $pdo->query("SHOW TABLES LIKE 'settings'"); if ($res->rowCount() == 0) { $sql_file = __DIR__ . '/install.sql'; if (file_exists($sql_file)) { $sql = file_get_contents($sql_file); $pdo->exec($sql); } } } } catch (PDOException $e) { die("Database connection failed: " . $e->getMessage()); } } return $pdo; }