【问题标题】:issue in inserting data into mysql database table : showing DB error将数据插入mysql数据库表的问题:显示数据库错误
【发布时间】:2015-12-13 01:17:06
【问题描述】:

我有一个名为 history 的数据库表,其架构如下:

CREATE TABLE IF NOT EXISTS `history` (
  `id` int(11) NOT NULL,
  `history_date` datetime DEFAULT NULL,
  `sql_query` text,
  `authuser` varchar(200) DEFAULT NULL,
  `ip` varchar(100) DEFAULT NULL,
  `authId` int(11) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=618 DEFAULT CHARSET=latin1;

我正在尝试在 php 中运行一个返回以下错误的脚本:

HIST DB Error :(INSERT into history(history_date,sql_query,ip,authuser,authId) VALUES(1441378485,'UPDATE itemstypes SET typedesc="Keyboard",hassoftware=0 WHERE id="10"','10.16.7.44','superadmin','6')):Incorrect datetime value:1441378485 for column 'history_date' at row 1

如果我通过本地主机的 phpmyadmin 运行查询 INSERT into history(history_date,sql_query,ip,authuser,authId) VALUES(1441378485,'UPDATE itemstypes SET typedesc="Keyboard",hassoftware=0 WHERE id="10"','10.16.7.44','superadmin','6'),它会被插入,但由于数据类型不匹配,在 history_date 列中,0000-00-00 00:00:00 正在存储。 现在,当我在实时服务器中运行相同的程序时,我收到了上述错误。 可能是什么问题?请告诉我。服务器中是否有任何配置问题?请帮帮我。

提前致谢。

【问题讨论】:

  • 1441378485 不是有效的日期时间,格式为 Y-m-d H:i:s

标签: php mysql configuration


【解决方案1】:

更改日期格式,例如

INSERT into history(history_date,sql_query,ip,authuser,authId)
VALUES(2015-09-16 00:00:00,'UPDATE itemstypes
SET typedesc="Keyboard",hassoftware=0 WHERE id="10"','10.16.7.44','superadmin','6')

【讨论】:

  • 我知道如果我更改日期,它会起作用,但为什么我的脚本在运行此查询后停止。通常它应该插入日期不正确的记录。你能告诉我我需要做的任何与ini文件相关的更改吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-05
  • 2023-04-11
  • 2014-08-04
  • 1970-01-01
  • 2013-01-27
  • 1970-01-01
  • 2019-06-29
相关资源
最近更新 更多