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 @   mofy  阅读(81)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示