我正在尝试解析xml字符串并将值作为新记录的属性插入表中。下面的代码和数据库在两个单独的服务器上,我已经从这个服务器成功选择了数据库中的记录,但是我在插入它们时遇到了问题。这是我的代码:
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('Connected to MySQL');
var xmlstring= '<message><username>Robert</username><beaconid>15</beaconid><timeanddate>2014-11-08 10:11:55</timeanddate><entry>false</entry><mindistance>10</mindistandistance></message>';
var message = new xmldoc.XmlDocument(xmlstring);
var username;
var beaconid;
var timeanddate;
var entry;
var mindistance;
var newrecord = {username: message.childNamed("username").val, beaconid: message.childNamed("beaconid").val, timeanddate: message.childNamed("timeanddate").val,
entry: message.childNamed("entry").val, mindistance: message.childNamed("mindistance").val};
var query = connection.query('INSERT INTO leavingorentering SET ?', newrecord, function(err, result) {
});
console.log(query.sql);
});
当我运行代码时,它会将其输出到终端:
Connected to MySQL
INSERT INTO leavingorentering SET `username` = 'Robert', `beaconid` = '15', `timeanddate` = '2014-11-08 10:11:55', `entry` = 'false', `mindistance` = '10'
然而,当我从mysql workbench连接到数据库并直接查询它时,记录不存在。我跟着this example将新记录插入数据库(ctrl + F&#34;付费&#34;如果你不能看到它),我使用了this parser。任何人都可以帮助我吗?