lua-resty-mysql icon indicating copy to clipboard operation
lua-resty-mysql copied to clipboard

How to insert DATETIME column data into mysql database

Open 9992800 opened this issue 9 years ago • 1 comments

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)

9992800 avatar Jan 12 '16 10:01 9992800

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.

bungle avatar Jan 12 '16 10:01 bungle