Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql查询中参数列表后的SyntaxError:缺少)_Mysql_Node.js_Express - Fatal编程技术网

Mysql查询中参数列表后的SyntaxError:缺少)

Mysql查询中参数列表后的SyntaxError:缺少),mysql,node.js,express,Mysql,Node.js,Express,我不熟悉node.js。我已成功连接MySQL数据库。我可以执行简单的select查询,但当我尝试使用多个JOIN进行查询时,它会在参数列表后抛出一个错误,即缺少) app.get('/quotes', function (req, res) { mc.query(`SELECT p.sku,pa.attribute_value as is_seen, pa1.attribute_value as rating,m.projects_unit_id as project_id,m.version

我不熟悉
node.js
。我已成功连接MySQL数据库。我可以执行简单的select查询,但当我尝试使用多个JOIN进行查询时,它会在参数列表后抛出一个错误,即缺少)

app.get('/quotes', function (req, res) {
mc.query(`SELECT p.sku,pa.attribute_value as is_seen, pa1.attribute_value as rating,m.projects_unit_id as project_id,m.version,sp.total_sale_price as total_price,
    p.published_on,im.image_url as image, im1.image_url as  pdf_link FROM my_designs m INNER JOIN product p on m.sku=p.sku and p.is_deleted=0 and p.is_published=1 
    INNER JOIN supplier_product sp on sp.product_id=p.product_id and sp.is_deleted=0 
    LEFT JOIN images im on im.`key`=m.sku and im.image_type=36 and im.is_deleted=0 
    LEFT JOIN images im1 on im1.`key` = m.sku and im1.image_type = 15 and im1.is_deleted=0 
    LEFT JOIN product_attributes pa on pa.common_id = p.sku and pa.is_deleted = 0 and pa.attribute_name = 'is_seen' 
    LEFT JOIN product_attributes pa1 on pa1.common_id = p.sku and pa1.is_deleted = 0 and pa1.attribute_name = 'rating' 
    WHERE m.user_id=? and m.is_deleted=0 and m.projects_unit_id is not null ORDER BY p.published_on DESC`, function (error, results, fields) {
    if (error) throw error;
    return res.send({ error: false, data: JSON.stringify(results), message: 'quote list.' });
}); });
请告诉我哪里出了问题。

您正在尝试使用。您需要在变量周围使用
$
,这就是您需要组合查询的方式

`Select * from Table where key = ${key} and otherkey = ${otherkey}`

因为您使用的是模板文本

  • 模板文本由
    反勾(``)
    括起(严重重音) 字符,而不是双引号或单引号
  • 模板文本可以包含占位符。这些由 美元符号和大括号
    (${expression})

因此,您必须使用
im.${key}
而不是im.`key`

所以,你的代码变成

app.get('/quotes', function (req, res) {

mc.query(`SELECT p.sku,pa.attribute_value as is_seen, pa1.attribute_value as rating,m.projects_unit_id as project_id,m.version,sp.total_sale_price as total_price,
    p.published_on,im.image_url as image, im1.image_url as  pdf_link FROM my_designs m INNER JOIN product p on m.sku=p.sku and p.is_deleted=0 and p.is_published=1 
    INNER JOIN supplier_product sp on sp.product_id=p.product_id and sp.is_deleted=0 
    LEFT JOIN images im on im.${key}=m.sku and im.image_type=36 and im.is_deleted=0 
    LEFT JOIN images im1 on im1.${key} = m.sku and im1.image_type = 15 and im1.is_deleted=0 
    LEFT JOIN product_attributes pa on pa.common_id = p.sku and pa.is_deleted = 0 and pa.attribute_name = 'is_seen' 
    LEFT JOIN product_attributes pa1 on pa1.common_id = p.sku and pa1.is_deleted = 0 and pa1.attribute_name = 'rating' 
    WHERE m.user_id=? and m.is_deleted=0 and m.projects_unit_id is not null ORDER BY p.published_on DESC`, function (error, results, fields) {
    if (error) throw error;
    return res.send({ error: false, data: JSON.stringify(results), message: 'Todos list.' });
    }
);

});
Ps:


正如你所知道的,其他人知道,键是一个
保留的词。

谢谢你的帮助。因此,在查询中,我使用了导致该错误的tilde字符。所以我把它改成了单引号,它起作用了。实际上,键是一个保留字。这就是抛出错误的原因。好吧,它可能会告诉你一些关于你的错误中的键的事情。
${key}
也是要使用的标准语法,因为如果你使用任何lint,
key
会抛出错误,所以你应该使用
${key}
@r93,如果你觉得有用,你可以接受并投票给我的答案。