<?php
session_start();

$host = 'localhost';
$dbname = 'drmdferdous_homoeo';  // Change to your DB name
$user = 'drmdferdous_homoeo';                  // Change as needed
$pass = 'drmdferdous_homoeo';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}

function getSetting($key, $pdo) {
    $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = ?");
    $stmt->execute([$key]);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    return $row ? $row['setting_value'] : null;
}

function getPotencyPrice($potency_num, $pdo) {
    $stmt = $pdo->prepare("SELECT price FROM potency_prices WHERE potency_number = ?");
    $stmt->execute([$potency_num]);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    return $row ? (float)$row['price'] : 0;
}

function getAllPotencyPrices($pdo) {
    $stmt = $pdo->query("SELECT potency_number, price FROM potency_prices ORDER BY potency_number");
    return $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
}
?>