node-mysql:多语句查询,ER_PARSE_ERROR
node-mysql: Multiple statement queries, ER_PARSE_ERROR
我正在尝试 运行 对 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 和 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..