在node.js中使用CURRENT_TIMESTAMP更新MySQL表 [英] Updating MySQL table with CURRENT_TIMESTAMP in node.js

查看:104
本文介绍了在node.js中使用CURRENT_TIMESTAMP更新MySQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用node-mysql从node.js更新MySQL数据库表.我想用CURRENT_TIMESTAMP更新一行的时间戳列.但是,node.js似乎没有使用以下代码进行任何更改:

I am using node-mysql to update a MySQL database table from node.js. I want to update the timestamp column of a row with CURRENT_TIMESTAMP. However, no changes seem to be made by node.js using the following code:

Node.js代码

client.query('UPDATE listings SET job_checkout_timestamp = CURRENT_TIMESTAMP WHERE listing_id = 1515');

但是如果我要用JavaScript时间函数(例如new Date()

But works if I were to replace CURRENT_TIMESTAMP with a javascript time function, like new Date()

client.query('UPDATE listings SET job_checkout_timestamp = ? WHERE listing_id = 1515', [ new Date() ]);

但是,如果我要直接在mysql中执行相同的SQL查询(使用Navicat),则该行将使用当前时间戳进行更新!

However, if I were to execute the same SQL query directly into mysql (using Navicat), the row gets updated with the current timestamp!

直接SQL查询

UPDATE listings SET job_checkout_timestamp = CURRENT_TIMESTAMP WHERE listing_id = 1515;

某处出了什么问题吗?

推荐答案

似乎node.js可能会将输入变量转换为字符串,
并将current_timestamp设置为字符串而不是mysql变量,
通过将current_timestamp替换为同义词函数调用,如:-

It seems that node.js might convert the input variables into string,
and make the current_timestamp as string rather than mysql variables,
by replace the current_timestamp to synonym function call like :-

now()
current_timestamp()

应该解决问题

这篇关于在node.js中使用CURRENT_TIMESTAMP更新MySQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆