在NodeJs中做这类事情的事实上的方法是什么:
con.query("""
update something
set aaa = ???,
bbb = ???,
where ccc = ??? and ddd = ???
""", function (err, result) {
我的意思是,我怎样才能将这些值替换为sql请求正确并且很容易?
答案 0 :(得分:0)
您可以按以下方式申请代码:
var sql = phpjs.strtr("SELECT * FROM :table WHERE id = :id",
{
":table" : my_table,
":id" : my_id
}
);
myClient.query(sql, callback);
示例:
var sql = phpjs.strtr("UPDATE something SET aaa = :a, bbb = :b WHERE ccc = :c AND ddd = :d",
{
":a" : my_a,
":b" : my_b,
":c" : my_c,
":d" : my_d
}
);
con.query(sql, function (err, result){
//stmt
});