首页 > 解决方案 > 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配置选项有关吗?

标签: mysqlnode.js

解决方案


推荐阅读