Node.js MySQL Update

Node.js MySQL Update 

MySQL package is used to update data into table in mysql using node js.

UPDATE mysql statement is used to update data into table in mysql database.

Example : 

const mysql = require('mysql');

const db = mysql.createConnection({

     host: "localhost",
     user: "root",
     password: "*******",
     database : "aryadb"

  });

// connect to database

db.connect((err) => {

    if (err) {

        throw err;

    }else{

     console.log('Connected to database!');

     db.query("update employee set emp_addrees ='ahmedabad, india' where emp_id=1", function (err, result) {
          if (err) throw err;
              console.log("Updated record : "+result.affectedRows);
          }); 
    }

});

Write above code in server.js file and run this program as below.

D:\nodejs\website> node server.js  

It gives output as below.

Updated record : 1

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

63850