我有以下脚本:
radioStation.on('metadata', function(metadata) {
var values = (metadata.StreamTitle).split('-').map(i=>i.trim());
var artist = values[0];
var title = values[1];
console.log('webstream');
console.log(artist);
console.log(title);
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "radio"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO webstream (artist, title) VALUES ( " + artist + " ," + title + ")";
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
});
执行脚本时,我将收到ER_PARSE_ERROR。
有人知道我在做什么错吗?
答案 0 :(得分:0)
@Steve在正确的轨道上。也许这会有所帮助:
var sql = "INSERT INTO webstream (artist, title) VALUES ( '" + artist + "', '" + title + "')";