mysql 不接受“?”作为绑定运算符
mysql does not accept "?" as bind operator
正在尝试 运行 更新数据库的查询,由于某种原因,MySQL returns:
Error Code: 1064. 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 '?' at line 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"));
版本:
如果您有两列,则需要 tiw 个值
INSERT INTO eu_profile (id, profileName) VALUES (?,?)
另外 [profileData]
需要 2 个值,例如 [req.body.topic, req.body.note]
正在尝试 运行 更新数据库的查询,由于某种原因,MySQL returns:
Error Code: 1064. 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 '?' at line 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"));
版本:
如果您有两列,则需要 tiw 个值
INSERT INTO eu_profile (id, profileName) VALUES (?,?)
另外 [profileData]
需要 2 个值,例如 [req.body.topic, req.body.note]