express mysql转义 问号 数组占位符

情况一
arr=['a','b']

sql="select * from student where name in (?)"

db.query(sql,arr,function(){

    console.log(this.sql)

})
// select * from student where name in ('a'),只识别到数组的第一个

情况二
arr=['a','b']

sql="select * from student where name in (??)"

db.query(sql,arr,function(){

    console.log(this.sql)

})
// select * from student where name in (`a`,`b`),识别出来为反引号,语句执行报错

情况三,这种是数组占位符的写法
arr=['a','b']

sql="select * from student where name in (??)"

db.query(sql,[arr],function(){

    console.log(this.sql)

})
// select * from student where name in ('a','b),识别到整个数组

 

posted @ 2023-05-04 15:16  mofy  阅读(77)  评论(0编辑  收藏  举报