#1 2016-12-18 01:23:46

vga
Member
Registered: 2016-08-18
Posts: 15

Insert Record with Mysql Server Time

I use Delphi 2007 , Mysql 5.6,

CREATE TABLE `t_appstaffonline` (
    `App_ID` INT(11) NOT NULL AUTO_INCREMENT ,
    `Staff_ID` INT(11) NULL DEFAULT NULL,
    `AppName` VARCHAR(50) NULL,
    `IP` VARCHAR(50) NULL DEFAULT NULL,
    `Online` INT(11) NULL DEFAULT 0,
    `UpdateTime` TIMESTAMP NULL',
    `LastLoginTime` TIMESTAMP NULL,
    `LastLogOutTime` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`App_ID`),
    UNIQUE INDEX `Idx_SAP` (`Staff_ID`, `AppName`)
);


I want to set   LastLoginTime to DBServer's time, 
so my SQL Statement:

'insert into `t_appstaffonline`(Staff_ID, IP, AppName, OnLine, LastLoginTime)' +
'values(?,?,?,?,?)',[1, '127.0.0.1', 'app.exe', 1, 'now()']);

but this does not work,  and

'insert into `t_appstaffonline`(Staff_ID, IP, AppName, OnLine)' +
'values(?,?,?,?)',[1, '127.0.0.1', 'app.exe', 1]);

work fine, why

Last edited by vga (2016-12-18 01:54:20)

Offline

#2 2016-12-18 21:02:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Insert Record with Mysql Server Time

'now()' is a string, not a date/time value.

Offline

#3 2016-12-18 21:52:33

vga
Member
Registered: 2016-08-18
Posts: 15

Re: Insert Record with Mysql Server Time

thank you.

How can I fill the value of the field LastLoginTime with mysql server time "now()" when insert record to the table?

Last edited by vga (2016-12-18 21:53:57)

Offline

#4 2016-12-19 22:06:31

vga
Member
Registered: 2016-08-18
Posts: 15

Re: Insert Record with Mysql Server Time

ok,

ExecuteSQL(
      'insert into `t_appstaffonline`(Staff_ID, IP, AppName, OnLine, LastLoginTime)' +
      'values(?,?,?,?,now())',[1, '127.0.0.1', 'app.exe', 1]);


this work fine.

Last edited by vga (2016-12-19 22:07:35)

Offline

Board footer

Powered by FluxBB