【发布时间】:2013-08-04 01:21:15
【问题描述】:
我想在我的日期时间字段中保存日期 对于插入我没有问题... 我尝试了很多次,这是最后一次但结果是一样的
插入:
var now = new Date();
var jsonDate = now.toJSON();
var then = new Date(jsonDate);
var o_voto_foto = {
profilo_id: profilo,
foto_id: data.id_foto_votata,
punteggio: data.voto,
proprietario_id: data.proprietario_foto,
created: then
};
connection.query('INSERT INTO prof_voto_foto SET ?', o_voto_foto, function(error, rows) {
if (error) {
var err = "Error on INSERT 'votoFotoFancybox': " + error;
console.error(err);
throw err;
}
更新表格:
var now = new Date();
var jsonDate = now.toJSON();
var then = new Date(jsonDate);
connection.query('UPDATE prof_voto_foto SET punteggio = ' + data.voto + ', created = ' + then +' WHERE profilo_id = ' + profilo + ' AND foto_id = ' + data.id_foto_votata, function(error, rows) {
if (error) {
var err = "Error on UPDATE 'votoFotoFancybox': " + error;
console.error(err);
throw err;
}
我收到此错误:
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Aug 02 2013 19:03:13 GMT+0200 (CEST) WHERE profilo_id = 103 AND foto_id = 5' at line 1
【问题讨论】:
-
除非您使用参数化查询,否则不要忘记对您的所有值调用
connection.escape。
标签: javascript mysql node.js