lua-resty-mysql
lua-resty-mysql copied to clipboard
How to insert DATETIME column data into mysql database
error: "Incorrect datetime value: 'Tue Jan 12 18:31:10 2016' for column 'createTime' at row 1"
table:
CREATE TABLE jctx_group_members (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
groupId int(20) unsigned NOT NULL,
uid int(11) NOT NULL,
createTime datetime NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
code: local current_time = os.date()
local sql_create = "insert into jctx_group_info"
.."(creatorUid, groupName, createTime) values ("
..groupCreator..",\'"..groupName.."\',\'"..current_time.."\')"
local res, err, errno, sqlstate = self.database:query(sql_create)
I think DATETIME needs to be: '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
'Tue Jan 12 18:31:10 2016' is obviously not like that.