Skip to content

Commit a2305f0

Browse files
committedMay 2, 2020
UPDATE Query
1 parent b535ac2 commit a2305f0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

Diff for: ‎nodejs-mysql/update-record.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
let db_pool = require('./config').mysql_connect;
22

3-
let sql = `UPDATE employee SET city = 'Ranchi' WHERE id = ?`;
3+
let sql = `UPDATE employee
4+
SET city = ?
5+
WHERE id = ?`;
6+
7+
let data = ['Bangalore', 5];
48

59
// connect to the MySQL server
610
db_pool.getConnection((err) => {
711
if (err) throw err;
812

9-
// execute the SQL QUery
10-
db_pool.query(sql, [10], (err, result) => {
11-
if (err) throw err;
13+
// execute the UPDATE statement
14+
db_pool.query(sql, data, (error, result) => {
15+
if (error){
16+
return console.error(error.message);
17+
}
1218

1319
console.log(result.affectedRows + " record(s) updated");
1420
});

0 commit comments

Comments
 (0)