<?php
// functions.php — shared helpers for HP Sale

// Escape output (HTML safe)
function esc($str) {
    return htmlspecialchars($str ?? '', ENT_QUOTES, 'UTF-8');
}

// Clean input for SQL
function clean($conn, $value) {
    return mysqli_real_escape_string($conn, trim($value ?? ''));
}

// Fetch single row
function fetchRow($conn, $sql) {
    $rs = mysqli_query($conn, $sql);
    return ($rs && mysqli_num_rows($rs)) ? mysqli_fetch_assoc($rs) : null;
}

// Fetch multiple rows
function fetchRows($conn, $sql) {
    $rs = mysqli_query($conn, $sql);
    $rows = [];
    while ($rs && $row = mysqli_fetch_assoc($rs)) {
        $rows[] = $row;
    }
    return $rows;
}
