-- Refresh me --\n");
try{
$pdo = new PDO('mysql:host=mariadb;dbname=vhost;charset=utf8', "php", "Ew1RmFFqeZOA1zwkJkocAjmepQA4JmnUW0nqDFh79jHY8aubtPO_12E9wgbNvScX0Uiv1GuUllb8YCJ00PAoh0fvNS");
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_TIMEOUT, 5);
$pdo->setAttribute(PDO::ERRMODE_EXCEPTION, true);
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}catch(Exception $e){
printf("Cannot connect to database\n");
die();
}
// 1. Create table
$create = "CREATE TABLE IF NOT EXISTS nonce (
id_nonce int NOT NULL AUTO_INCREMENT PRIMARY KEY,
created_at int NOT NULL DEFAULT CURRENT_TIMESTAMP
);";
if( $errcode = $pdo->exec($create) > 0 ){
printf("* [%d] cannot create table\n\n", $errcode);
die();
}
// 2. Insert new line
$pr = $pdo->prepare("INSERT INTO nonce(id_nonce, created_at) VALUES(DEFAULT, :tnow);");
if( $pr !== false ){
$ok = $pr->execute([":tnow" => time()]);
if( !$ok ){
printf("* cannot insert data\n\n");
}
}else{
printf("* cannot insert data\n\n");
}
// 3. select all
$st = $pdo->query("SELECT * FROM nonce ORDER BY id_nonce DESC LIMIT 100;");
if( $st !== false ){
$nonces = $st->fetchAll();
printf("\n");
$max = count($nonces);
foreach( $nonces as $key=>$value ){
if( $key == 0 ){
printf("YOU ARE EXACTLY THE %dth VISITOR, CLICK HERE TO WIN THE PRIZE !!\n%s\n", $value['id_nonce'], date('H:i:s d/m/Y', $value['created_at']));
printf("\nWow ! Got lucky\n\n");
continue;
}
printf("%s | You are the %dth visitor, click here to win the prize !!\n", date('H:i:s d/m/Y', $value['created_at']), $value['id_nonce']);
}
printf("
\n");
}else{
printf("* cannot fetch data\n\n");
}
?>