对不起,如果之前已经询问过,或者我无法以很好的方式解释。我花了好几个小时试图绕过这个问题,而我似乎无法解决这个问题。代码在本地工作正常,但是当我将它上传到我的服务器时,服务器如何处理/检查服务器和客户端之间的时间差异似乎存在某种问题。不确定如何或想什么。我也意识到我不正确地将数据插入到pdo语句中,目前我不在意这一点。稍后我会整理所有这些。与客户端和服务器的时间/日期差异?
我遇到问题的应用程序的部分是检查活动的货件(这是某种游戏)。我想比较数据库中的时间戳和当前时间,看看时间是否已经过去。在到货时间过去的情况下,我希望将货件的状态设置为“交付”,并将数据添加到另一个名为“存储”的表中。
function check_active_shipment(){
$pdo = pdo();
$username = $_SESSION['username'];
$statement = $pdo->prepare("SELECT * FROM shipments WHERE username LIKE '$username' AND status LIKE 'active' LIMIT 1");
$statement->execute();
$rows = $statement->fetch();
$id = $rows['id'];
if($rows['type'] == "purchase"){
if(time() >= strtotime($rows['arrival'])){
$statement = $pdo->prepare("UPDATE shipments SET status='delivered' WHERE id LIKE '$id'");
$statement->execute();
$statement = $pdo->prepare("INSERT INTO storage (username, crate_type_id, quantity) VALUES (?, ?, ?)");
$statement->bindParam(1, $username);
$statement->bindParam(2, $rows['crate_type_id']);
$statement->bindParam(3, $rows['quantity']);
$statement->execute();
//header("location:index.php");
}
}
else if($rows['type'] == "sale"){
if(time() >= strtotime($rows['arrival'])){
$statement = $pdo->prepare("UPDATE shipments SET status='delivered' WHERE id LIKE ?");
$statement->bindParam(1, $id);
$statement->execute();
$statement = $pdo->prepare("SELECT cash FROM users WHERE username LIKE ?");
$statement->bindParam(1, $username);
$statement->execute();
$user = $statement->fetch();
$cash = $user['cash'] + $rows['value'];
$statement = $pdo->prepare("UPDATE users SET cash=?");
$statement->bindParam(1, $cash);
$statement->execute();
//header("location:index.php");
}
}
}
让我知道是否有任何信息我想失去分享。
是您的数据库托管在其他服务器上?如果是这样,它是否托管在具有不同时间/时区的服务器上? –
查询时区。 – eronax59
一切都在同一台服务器,文件和数据库上。我不知道它是什么时区,但考虑到服务器在斯德哥尔摩我假设欧洲/斯德哥尔摩。关于如何找出服务器/数据库时区的任何想法? –