javascript 无法使用Nodejs从数据库获取总行数

ff29svar  于 2023-05-12  发布在  Java
关注(0)|答案(1)|浏览(136)

我正在使用Nodejs/Express,现在我正在尝试从数据库中获取总记录,但我得到的是“无/空”,这是我的模型文件代码,我错在哪里?

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 empty
        if(rows<1)
            {
                  //further code  
            }
    }
qjp7pelc

qjp7pelc1#

没有更多的代码很难,但我注意到你的genderTypeId应该在${}中吗?:
出发地:

const sql = `SELECT id from hc_servicesdetail WHERE shopId='${shopId}' AND  serviceId='${serviceId}' AND genderTypeId='genderTypeId'`;

收件人:

const sql = `SELECT id from hc_servicesdetail WHERE shopId='${shopId}' AND  serviceId='${serviceId}' AND genderTypeId='${genderTypeId}'`;

相关问题