the problem for Mysql

60 views
Skip to first unread message

hanx...@qq.com

unread,
Jan 8, 2016, 12:29:07 AM1/8/16
to Express
in my project.i use mysql like this:
var user = {
getAllUserList:'select * from ad_user where name = ? and address = ?'
}
and i can get result list this:
var query = connection.query(user.select,[param.name,param.address],function(err,result){
    if(result){
....
}
});
but if i only have one parameter,Name or addresss.How to write the sql.

Regards,
Jiff Han 

Ryan Schmidt

unread,
Jan 9, 2016, 6:54:24 AM1/9/16
to expre...@googlegroups.com
Well, if you only have the parameter "name", then the SQL would be "SELECT * FROM ad_user WHERE name = ?" and you would invoke connection.query(user.select, [param.name], function (err, result) {...});

梁少峰

unread,
Mar 13, 2016, 10:50:57 AM3/13/16
to Express
What about define two sql query? One for select name,anthor for select address.
You can choose which sql query to use according to the param.
May it help.

在 2016年1月8日星期五 UTC+8下午1:29:07,hanx...@qq.com写道:
Reply all
Reply to author
Forward
0 new messages