I am trying to save xml string to MySQL database here is my code:- I am using MySQL module for manage database;
//I am reading the xml file from path using this code
var stream = fs.createReadStream(path);
stream.setEncoding('utf8');
stream.on('data', function (chunk) {
var text=chunk.toString('utf8');
//here is the error i.e invalid syntax in MySQL query
con.query('insert into table_name(text) values("'+text+'")',function(err,data){
//allways getting error.
});
});
I know the error because of invalid characters in text variable. So how I can concatenate or escape the string please help me.
Thanks