我使用此代码作为 PayPal 的 ipn 消息,PayPal 响应交易成功并已验证。然后,交易详细信息将被插入到 MySQL 数据库中。一切都按照我想要的方式工作,除了 MySQL 时间戳与正确的时区不匹配。我的时区是“美国/芝加哥”,但时间戳早 1 小时。我维护的一些网站关闭时间超过 3 小时。这是我的代码尝试在插入之前设置 MySQL 时区。 数据库中发布的最新交易包含此信息,2024 年 4 月 11 日上午 07:21:15,但我所在时区的正确时间是上午 08:21
<?php require_once('Connections/connstake.php'); ?>
<?php
// After establishing the DB connection
mysqli_query($connstake,"SET time_zone='America/Chicago'");
// Now proceed with the insert
if (true) {
$InsertQuery = new WA_MySQLi_Query($connstake);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "registration_paypal";
$InsertQuery->bindColumn("transaction_ID", "s", "".$_POST['txn_id'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("first_name", "s", "".$_POST['first_name'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("last_name", "s", "".$_POST['last_name'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("email1", "s", "".$_POST['payer_email'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("address_street", "s", "".$_POST['address_street'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("address_city", "s", "".$_POST['address_city'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("address_state", "s", "".$_POST['address_state'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("address_zip", "s", "".$_POST['address_zip'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("amount", "d", "".$amount ."", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_gross", "s", "".$_POST['mc_gross'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("payment_fee", "s", "".$_POST['mc_fee'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("special_requests", "s", "".$_POST['memo'] ."", "WA_DEFAULT");
$InsertQuery->bindColumn("original_request", "s", "".http_build_query($_POST) ."", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
时间戳的插入不会显示在代码中,因为它是由 WA_MySQLi_Query 在后台自动插入的
我已经找到答案了,它与我的 ipn 中的代码没有任何关系。我在 MySQL 的 stackoverflow 上读到,时间戳和日期时间之间的差异以及检查在线交易的日期时间正是我需要的,以使付款日期与客户端的时区完全匹配。