gpt4 book ai didi

php - 如何将当前时间戳插入数据库?

转载 作者:行者123 更新时间:2023-11-29 17:11:39 25 4
gpt4 key购买 nike

我一直在尝试这个查询和研究,但我不明白为什么它不起作用。

IP记录(VARCHAR)保存在数据库的表中,但插入记录时无法保存记录DATETIME

$sql = "INSERT INTO ips (ip, fecha) VALUES (:ip, :CURRENT_TIMESTAMP)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':ip' => htmlentities($_POST['ip']),
':CURRENT_TIMESTAMP' => htmlentities(CURRENT_TIMESTAMP)
));

最佳答案

使用PHP的时间函数:

$sql = "INSERT INTO ips (ip, fecha) VALUES (:ip, :CURRENT_TIMESTAMP)";
$t = time();
$today = date("Y-m-d", $t);
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':ip' => htmlentities($_POST['ip']),
':CURRENT_TIMESTAMP' => $today

关于php - 如何将当前时间戳插入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51864679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com