mysql - mysql 插入错误:ER_PARSE_ERROR:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册
问题描述
错误:ER_PARSE_ERROR:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的 '' 附近使用正确的语法
我的代码中有 2 个 mysql 插入函数。当我的第二个插入函数没有要插入的内容并且没有被调用运行时,我收到此错误消息。如果两个插入函数都有要插入的数据,则程序可以正常工作并且没有错误消息。
我尝试将包含连接详细信息设置的配置文件修改为mysql并设置multipleStatements:true,但这没有帮助。当我在 mysql 中运行它们时,这两个插入语句都有效。
let sql = `INSERT INTO stock_feed_periodic (symbol,price,ts) VALUES ?`;
insertValuesToDB(sql, values);
let sql2 = `INSERT INTO stock_feed_unusuals (symbol,price,ts) VALUES ?`;
if (unusuals) insertValuesToDB(sql2, unusuals);
function insertValuesToDB(sql, values) {
conn.query(sql, [values], function(err, res) {
if (err) throw err;
return;
});
}
config.js 文件: const mysql = require("mysql");
// create a connection variable with the required details
const conn = mysql.createConnection({
host: "localhost", // ip address of server running mysql
user: "****",
password: "*****",
database: "stocks"
});
module.exports = conn;
我只在对象异常未定义时才收到消息,然后第二个函数不应该运行。如果已定义,则两个插图都可以正常运行。很奇怪。它与mysql配置选项有关吗?
解决方案
推荐阅读
- laravel - 如何在同一列中加入具有多个 id 的表?
- excel - 即使 Application.On 时间安排已关闭,Excel 文件也会一直打开
- javascript - 从 nextcloud api 获取用户信息
- python - 提取重复的 JSON 标签
- python - 如何在 Jupyter 笔记本中将视频文件的帧显示为 gif 而无需写入文件
- sql - SQL查询 - 填充缺失值
- python - EarlyStopping 是否采用最后一个时期或最后最好成绩的模型?
- php - 在 Woocommerce 管理订单页面中更改文本“计费”和“运输”
- dll - 在 Inno Setup 中加载具有依赖项的 DLL 在卸载程序中失败并显示“无法导入 DLL”,但在安装程序中有效
- sql - 获取最新的 ModifiedDate 加入多个表