gpt4 book ai didi

mysql - node-mysql:多语句查询,ER_PARSE_ERROR

转载 作者:行者123 更新时间:2023-11-29 07:17:35 25 4
gpt4 key购买 nike

我正在尝试对 MySQL 数据库运行多语句查询。我正在使用 node-mysql 和 ExpressJS。我通过将 multipleStatements 设置为 true 启用了多语句查询:

const connection = mysql.createPool(config.databaseOptions, {multipleStatements: true});

我有以下多语句查询:

app.get('/information', urlencodedParser, function (req, res) {
var mysql = require('./resources/mysqlConnection');

var qry = "SELECT e.emp_id, company_id, age, country FROM employee as e INNER JOIN company as c ON e.emp_id = c.emp_id WHERE e.emp_id = ?;SELECT * from players as p INNER JOIN teams as t ON p.team_id = t.team_id WHERE country = ?";

mysql.query(qry, ["E00909", "Japan"], function(err, rows) {
if (err) throw err;
console.log(rows);
var emp_data = rows[0];
var team_data = rows[1];
res.render('info.ejs', {data : emp_data});
});

});

但是,当我运行服务器时,出现以下错误:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * from players as p INNE'

我读过其他关于多语句查询的帖子,但所有这些情况的解决方案是通过将 multipleStatements 设置为 true 来启用多语句查询。我已经这样做了,所以我不确定为什么会出现此错误。我认为代码中的 ["E00909", "Japan"] 数组是此问题的根源,但我不确定如何解决它。进一步将数组写为 ['E00909', 'Japan'] 并没有解决问题。任何见解都值得赞赏。

最佳答案

我会尝试在您的 config.databaseOptions 对象中设置选项,例如

const config = {
databaseOptions: {
host: "some_host",
user: "some_user",
password: "some_pw",
database: "some_db",
multipleStatements: true
}
}

或者只是尝试:

config.databaseOptions.multipleStatements = true;

在创建池之前。

这为我解决了错误!

如果我省略这一行,我会得到和你一样的错误:

ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT..

关于mysql - node-mysql:多语句查询,ER_PARSE_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58410791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com