-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_mysql.js
70 lines (60 loc) · 1.45 KB
/
database_mysql.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'visualmedia',
database : 'o2'
});
connection.connect();
/* SELECTING
var sql = 'SELECT * FROM topic';
connection.query(sql, function(err, rows, fields){
if(err){
console.log(err);
} else {
for (var i=0; i<rows.length; i++){
console.log(rows[i].title);
console.log(rows[i].author);
}
}
});
*/
/* INSERT
var sql ='INSERT INTO topic (title, description, author) VALUES (?, ?, ?)';
var params = ['Supervisor','Watcher','graphittie'];
connection.query(sql, params, function(err, rows, fields){
if(err){
console.log(err);
} else {
console.log(rows.insertId);
}
});
*/
/* UPDATE
var sql ='UPDATE topic SET title=?, author=? WHERE id=?';
var params = ['NPM','leezche', 1];
connection.query(sql, params, function(err, rows, fields){
if(err){
console.log(err);
} else {
console.log(rows);
}
});
*/
var sql = 'DELETE FROM topic WHERE id=?'
var params = [1];
connection.query(sql, params, function(err, rows, fields){
if(err){
console.log(err);
} else {
console.log(rows);
}
});
connection.end();
//connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
// if (err) throw err;
//
// console.log('The solution is: ', rows[0].solution);
//});
//
//connection.end();