在$ _SESSION中获取timestamp mysql值

时间:2013-03-22 15:43:07

标签: php mysql session timestamp

$qry = "SELECT user, TIME_FORMAT(last_login_time, '%H:%i') FROM login_attempts WHERE user = '".$username."'";
$result = mysql_query($qry,$this->connection);
if(!$result || mysql_num_rows($result) <= 0){
    mysql_query ("INSERT INTO login_attempts(userid, user, attempts, last_login_time) VALUES('', '$username', '{$_SESSION['count']}', '{$_SESSION['login_time']}')");           
}
else{                   
    $row = mysql_fetch_assoc($result);
    $_SESSION['login_time'] = $row["last_login_time"];
    mysql_query ("UPDATE login_attempts SET attempts = '" .$_SESSION['count']."' WHERE user = '".$username."'");            
}

在上面的代码中,我将$_SESSION['login_time']值存储在“login_attempts”表中,其中列名为“last_login_time”。

现在我需要获取此值并将其存储回$_SESSION['login_time']数组中,以便我知道用户上次尝试输入的时间。我该怎么取这个值???

'last_login_time'列的数据类型为'timestamp'.

1 个答案:

答案 0 :(得分:1)

您需要为TIME_FORMAT列添加别名才能引用它。

SELECT user, TIME_FORMAT(last_login_time, '%H:%i') AS last_login_time ...

另外,为什么不UPDATE登录尝试SET attempts = attempts + 1