mysql不接受“?”作为绑定运算符

问题描述

尝试运行查询以更新数据库,由于某种原因,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"));

版本:

enter image description here

解决方法

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

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

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