我正在使用Nodejs和expressjs,现在我正在尝试执行select query,query正在成功工作,但我想要两件事
1) How to convert this query to "paramerized query" ?
2) Whenever i am trying to get "total rows" then i am getting "[object object] "
下面是我的当前代码
static async addServiceDetail(shopId,serviceId,genderTypeId,price,serviceName)
{
const sql = `SELECT id from hc_servicesdetail WHERE shopId='${shopId}' AND serviceId='${serviceId}' AND genderTypeId='${genderTypeId}'`;
const [rows, fields] = await pool.execute(sql);
console.log('total rows are'+ rows); // getting [object object]
if(rows<1)
{
//further code
}
}
2条答案
按热度按时间anauzrmj1#
您可以将参数作为数组传递给
execute
调用,然后将行记录到控制台:输出结果如下所示:
svdrlsy42#
要打印包含在results中的值,只需使用results。