在node.js项目中用到mysql数据库;然后查询一张表的数据,代码如下
//查询所有的合作用户 Cooperativeuser.queryAll = function queryAll(searchParams,callback){ var _queryAllSql = ""; if(typeof(searchParams)=="string"||typeof(searchParams)=="object" ){ if(null!=searchParams&&""!=searchParams){ _queryAllSql = "select * from cooperativeuser where state = 1 and companyName like '%"+searchParams+"%' or updateMan like '%"+searchParams+"%' "; } }else{ _queryAllSql = "select * from cooperativeuser where state = 1 "; } mysql.query(_queryAllSql,function(err, results, fields){ if(err){ callback(err) }else{ callback(err, results, fields); } }); };
运行的时候报 TypeError: undefined is not a function,在度娘上搜索,预计是callback被多次调用的缘故,但是不知道怎么去解决,希望路过的大神帮忙下,谢谢
学习是最好的投资!