javascript - How do I update multiple rows using an array in mysql using node js -


i'm trying use update update 3 different columns in table(stores). add openingtime, closingtime, , phonenumber...but want them added via storeid, exists in table. need make individual call each entry based on storeid. or possible me make single call table , loop through each storeid?

here's have far.

var arraythatcontainseverything = [];  var locations = ["randoma", "randomb", "randomc", ]; var openingtime = ["10:00", "10:00", "10:00"]; var closingtime = ["24:00", "24:00", "24:00"]; var phonenumber = ["123-4567", "123-6789", "123-9999"]; var ids = ["210", "213", "234"];   var q = 'update stores set openingtime=?, closinghours=?, phonenumber=?  storeid=?'; con.query(q, [array contains everything], function(err, results){ if(err) console.log(err);  if (debug >= 2 )console.log("finished inserting hours , phone number database");                 con.end(); )}; 

support multiple statements disabled security reasons (it allows sql injection attacks if values not escaped). use feature have enable connection:

var connection = mysql.createconnection({multiplestatements: true}); 

here mysqljs multiple statement queries documentation

once enabled, have build (multiple statement) query string.

its easy, if going loop build each independent query , append final query string, suggest using underscore's each.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -