lundi 2 mars 2020

php mysql automatic update column value after specific time

it's member system...

when member login, mysql column "IsActive" will be change value to 1

and LastActivity will be current time e.g. 2020-03-02 21:26:11

.

when member click logout button, "IsActive" will be change value to 0

but if member just close window without click logout button?

.

i want mysql automatic change "IsActive" to 0 after 15 minute base on LastActivity time

(LastActivity is always update when member change page)

------------------------ e.g.

LastActivity is 2020-03-02 00:00:00

IsActive will be change to 0 on 00:15:00

but if member change page on 00:14:00

LastActivity will be change to 2020-03-02 00:14:00

and IsActive will be change to 0 on 00:29:00

BASE ON LAST ACTIVITY TIME

.

nginx/1.16.1

MySQL Community Server - GPL - Server version: 8.0.19

PHP version: 7.4.2

.

THIS IS MY CODE (not working)

$serverName = "localhost";
$userName = "root";
$userPassword = "1234";
$dbName = "web";

$objCon = mysqli_connect($serverName,$userName,$userPassword,$dbName);

if (mysqli_connect_errno())
    {
        echo "Database Connect Failed : " . mysqli_connect_error();
        exit();
    }

//*** Reject user not online
$intime = 15;
$sql = "UPDATE member SET IsActive = '0' WHERE 1 (LastActivity, INTERVAL $intime MINUTE) <= NOW() ";
$query = mysqli_query($objCon,$sql);

thank you everyone.




Aucun commentaire:

Enregistrer un commentaire