<?php
// /linkstorm/inc/db.php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// change these to your actual cPanel MySQL credentials:
define('LS_DB_HOST', 'localhost');
define('LS_DB_NAME', 'heru_linkstorm');
define('LS_DB_USER', 'heru_heru');
define('LS_DB_PASS', 'Sungodra1*');

function ls_pdo() {
    static $pdo = null;
    if ($pdo === null) {
        $dsn = 'mysql:host=' . LS_DB_HOST . ';dbname=' . LS_DB_NAME . ';charset=utf8mb4';
        $pdo = new PDO($dsn, LS_DB_USER, LS_DB_PASS, [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        ]);
    }
    return $pdo;
}

function ls_current_user() {
    if (!isset($_SESSION['user_id'])) return null;
    return [
        'id'    => $_SESSION['user_id'],
        'email' => $_SESSION['user_email'] ?? ''
    ];
}
