1

尝试运行查询以更新数据库,由于某种原因,MySQL 返回:

错误代码:1064。您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在“?”附近使用的正确语法 在第 1 行

在 SQL 中尝试了该行以查看发生了什么

INSERT INTO eu_profile (id, profileName) VALUES ? 

它也会失败,并在代码中显示相同的消息:

import * as mysql2  from 'mysql2';
import * from 'mysql2/promise'

/** Lets open the database for mysql2 */
const mysql2connection = mysql2.createConnection({
    "host": "localhost",
    "port": 3306,
    "user": "node",
    "password": "NotTellingYou",
    "database": "stats"
});
mysql2connection.connect(function(error){
    if(!!error){
        console.log(error);
    }else{
        console.log('Connected!:)');
    }
});


    let dbTables: string="";
    let sqlInsert: string="";
    dbTables = "id, profileName";
    sqlInsert = "INSERT INTO eu_profile ("+dbTables+") VALUES ?"

    const profileLoad = await mysql2connection.query(sqlInsert, [profileData], function(err) {
        if (err) throw err{
        mysql2connection.end();
        }else
    }).then(console.log("We are done here"));

版本: 在此处输入图像描述

4

1 回答 1

2

如果您有两列,则需要 tiw 值

INSERT INTO eu_profile (id, profileName) VALUES (?,?) 

[profileData]需要 2 个值,例如[req.body.topic, req.body.note]

于 2020-08-22T18:23:05.413 回答