I had successful bulk insert rows into database by passing array of the objects into database. When comes to update, it doesn't work that way either.
Bulk Insert
var photos_array = [];
req.body.photos.forEach(function(photo){
photos_array.push([photo.menu_id, photo.name, photo.url])
})
connection.query('INSERT INTO ' + dbconfig.database + '.' + dbconfig.photos_table + ' (menu_id, name, url) VALUES ?', [photos_array], function(err, result){
if(result.affectedRows > 0){}
else{}
});
How to do bulk insert with a single query without multiple statements on MySQL? The reason I don't want to allow multiple statements on my codes is because to prevent SQL injection attacks. Or you have another better approaches are much more faster and secure, will be appreciated.
via Foonation
No comments:
Post a Comment