-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.js
42 lines (34 loc) · 1019 Bytes
/
query.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var mysql = require('mysql');
var con = mysql.createConnection({
host: "127.0.0.1",
user: "root",
password: "rootroot",
database: "mydb"
});
// con.connect(function(err) {
// if (err) throw err;
// con.query("SELECT * FROM charity", function (err, result, fields) {
// if (err) throw err;
// console.log(result);
// });
// });
con.connect(function(err) {
if (err) throw err;
var sql = "UPDATE mydb SET Balance = 1000 WHERE Charity = 'United'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result.affectedRows + " record(s) updated");
});
var sql = "DELETE FROM mydb WHERE Balance = 0";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Number of records deleted: " + result.affectedRows);
});
con.query("SELECT * FROM mydb", function (err, result, fields) {
if (err) throw err;
Object.keys(result).forEach(function(key) {
var row = result[key];
console.log(row.Balance)
});
});
});