PHP SQL sample codes for WEB05A

WEB05A youtube https://www.youtube.com/watch?v=cqWkipilCTk&ab_channel=AVEA

<?php

/*
    SQL database parameters
*/
$db_host = "localhost";     // SQL database server
$db_user = "your_username";  // SQL database username
$db_pwd = "your_password";   // SQL database password
$db_name = "your_database";  // SQL database

/*
    try to connect to the SQL database server
*/
if (!mysql_connect($db_host,$db_user,$db_pwd)) {
    die( "Unable to connect host");
}

/*
    try to open the database
*/
if (!mysql_select_db($db_name)) {
    die( "Unable to select database");
}

$now = time();                      // current time of web server
$st = date('Y-m-d H:i:s',$now);     // convert to proper format


/*
    get the parameters from the WEB05A
*/
$cmd = $_GET["cmd"];        
$date = $_GET["date"];
$time = $_GET["time"];
$dt = $date . ' ' . $time;

if ($cmd == "CO") {
    $code = $_GET["code"];      // get the RFID card number
    /*
        insert a record to the table logs of the database
    */
    $query = "INSERT INTO logs VALUES ($st, $dt, $cmd, $code)";
    $result = mysql_query($query);
    mysql_close();
    
    /*
        set response to the WEB05A
    */
    echo "<AVEA>";      // send starting flag
    echo "CK=$st";      // set the clock of WEB05A
    echo "GRNT=02";     // engage the relay of WEB05A for 2 seconds
    echo "</AVEA>";     // send closing flag
} else {
    /*
        set response to the WEB05A
    */
    echo "<AVEA>";      // send starting flag
    echo "CK=$st";      // set the clock of WEB05A
    echo "BEEP=0";      // make a beep sound on WEB05A
    echo "</AVEA>";     // send closing flag
}

?>