Hi anyOne.
I've got this php code
for a who online class
(I'm using a abstractDb class):
$currentTime = time();
$ip = $_SERVER['REMOTE_ADDR'];
$file = $_SERVER['PHP_SELF'];
$timeout = time() - 120;
$query = "DELETE FROM _usersonline WHERE time < $timeout";
$this->__DB->performQuery($query);
$query = "INSERT INTO _usersonline (time,remote_ip,file) VALUES ('".$currentTime."','".$ip."','".$file."')";
$this->__DB->performQuery($query);
with this sql:
CREATE TABLE `_usersonline` (
`time` INT( 11 ) DEFAULT '0' NOT NULL ,
`remote_ip` VARCHAR( 40 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT '0' NOT NULL ,
`file` VARCHAR( 100 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT '0' NOT NULL ,
INDEX ( `time` , `remote_ip` , `file` )
);
Now I'd lke to change the table in this way:
CREATE TABLE `_usersonline` (
`time` TIME DEFAULT '0' NOT NULL ,
`remote_ip` VARCHAR( 40 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT '0' NOT NULL ,
`file` VARCHAR( 100 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT '0' NOT NULL ,
INDEX ( `time` , `remote_ip` , `file` )
);
and the php code:
$ip = $_SERVER['REMOTE_ADDR'];
$file = $_SERVER['PHP_SELF'];
$query = "DELETE FROM _prova WHERE time < NOW()-120";
$this->__DB->performQuery($query);
$query = "INSERT INTO _prova (time,remote_ip,file) VALUES (NOW(),'".$ip."','".$file."')";
$this->__DB->performQuery($query);
I'm wondering is a faster way and above all
is it this query right:
$query = "DELETE FROM _prova WHERE time < NOW()-120";
I'd need a good link (tutorial) to manage query/field with time
data type as well I tried to find for it but .... guest you 😃
Take care.
Bye.