事实是,列(开始)设置为时间戳。
因此,我为插入查询编写了以下代码:
$query = "INSERT INTO {$this->table_name} (`user_id`, `name`, `code`, `start`, `city`, `state`, `groups`) VALUES ( :user_id, :name, :code, TIMESTAMP( :start ), :city, :state, :groups)";
$stmt = $this->connection->prepare($query);
$stmt->bindParam(":user_id", $this->user_id);
$stmt->bindParam(":name", $this->name);
$stmt->bindParam(":code", $this->code);
$stmt->bindParam(":start", $this->start);
$stmt->bindParam(":city", $this->city);
$stmt->bindParam(":state", $this->state);
$stmt->bindParam(":groups", $this->groups);
if ($stmt->execute()) { ........
除“组”外,所有变量均为字符串。'groups'是一个JSON。
出现以下错误:
“错误的日期时间值:'597492800'”
所以问题是为什么当列是时间戳记并且我要插入时间戳记时,为什么说不正确的日期时间。
即使当我尝试将时间戳设置为int时,它也不能解决问题。
$stmt->bindParam(":start", $this->start, PDO::PARAM_INT);
我正在从后端发送时间戳,并希望保存它。我不需要从某种格式到时间戳的任何转换,因为时间戳已经具有正确的格式。
我是sql世界的新手,这让我感到惊讶。如果您能帮助我,我会很高兴,因为我整天都在研究这一相对容易的插入内容。
(MySQL版本:8)
非常感谢!
TIMESTAMP()
接受一个date
或datetime
表达式,而597492800
不是一个这样的值。喜欢的东西'2020-08-12'
会。
该错误似乎很明显。
尚不清楚您想做什么-因为问题并不能解释这一点。我可能会推测您要将FROM_UNIXTIME()
数字转换为日期/时间值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句