<?php

require('pdo.php');

$dt_added = date('Y-m-d 00:00:00');

try {
    $stmt = $db->prepare("
        INSERT INTO games (name, provider_id, translit, demo_desk, demo_mob, volatility, rtp, rtp_low, rtp_high, max_win, link, dt_added) 
        VALUES (:name, :provider_id, :translit, :demo_desk, :demo_mob, :volatility, :rtp, :rtp_low, :rtp_high, :max_win, :link, :dt_added) 
        ON DUPLICATE KEY UPDATE  
        demo_desk = VALUES(demo_desk),
        demo_mob = VALUES(demo_mob),
        volatility = VALUES(volatility),
        rtp = VALUES(rtp),
        rtp_low = VALUES(rtp_low),
        rtp_high = VALUES(rtp_high),
        max_win = VALUES(max_win),
        link = VALUES(link),
        dt_added = IF(dt_added IS NULL, VALUES(dt_added), dt_added)
    ");

    $stmt->execute([
        ':name' => $name,
        ':provider_id' => $provider_id,
        ':translit' => $translit,
        ':demo_desk' => $demo_desk,
        ':demo_mob' => $demo_mob,
        ':volatility' => $volatility,
        ':rtp' => $rtp,
        ':rtp_low' => $rtp_low,
        ':rtp_high' => $rtp_high,
        ':max_win' => $max_win,
        ':link' => $link,
        ':dt_added' => $dt_added
    ]);
} catch (PDOException $e) {
    // Handle the exception here, e.g., log the error message
    echo "PDOException: " . $e->getMessage();
    // You can take additional error-handling actions here as needed
}

?>
