将csv的NOW()和文件名添加到同一个mysql列中

时间:2017-02-21 11:28:23

标签: php mysql

on import我想把csv的名称和导入日期放在同一列名中,

在我的代码上我有错误,因为$ filename和NOW()不能在thist代码的同一列中:

"LOAD DATA LOCAL INFILE '$filename' 
INTO TABLE $databasetable 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(name, firstname)
SET batch = $filename NOW() ");

2 个答案:

答案 0 :(得分:2)

这可以通过使用mysql CONCAT函数来解决:

SET batch = CONCAT($filename, ' ', NOW())

答案 1 :(得分:0)

您需要将$ filename的值与now()的值正确连接。老实说,我会在php中这样做,而不是在sql中,但你也可以在sql中这样做:

$t=date(DATE_ATOM)
...
SET batch = '$filename $t'

在php中:

var sendMail = function (templateName, recipients, templateParameters, attachments, subject) {

return mailingExternalTemplateModel.findMailingTemplateId(templateName)
    .then( (result) => {
        var params = {
            "FromEmail": nodeMailjet.mailjetFromMail,
            "FromName": nodeMailjet.mailjetFromName,
            "Subject": subject,
            'MJ-TemplateID': result,
            'MJ-TemplateLanguage': true,
            "Recipients": recipients,
            "Vars": {
                'username': templateParameters.username,
                'hello': i18n.__('email.hello'),
                'voucher_details': i18n.__('email.voucher_details'),
                'email_footer': i18n.__('email.footer.i_love_my_price')
            }
        };

        if (attachments) {
            params.Attachments = attachments;
        }

        return mailjet
            .post("send")
            .request(params)
            .then((result) => {
                return result.body; //***** If i comment here then still test case goes green which should fail. so how i achive that?
            });
    })
    .catch( (err) => {
        return Promise.reject(err);
    });
};