forked from steven37788/stock_dde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_test.js
59 lines (49 loc) · 1.58 KB
/
mysql_test.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
var logger = require('./applog').logger;
var mysql = require('mysql');
var conn = mysql.createConnection({
host: 'localhost',
user: 'nodejs',
password: 'nodejs',
database:'nodejs',
port: 3306
});
conn.connect();
var insertSQL = 'insert into t_user(name) values("conan"),("fens.me")';
var selectSQL = 'select * from t_user limit 10';
var deleteSQL = 'delete from t_user';
var updateSQL = 'update t_user set name="conan update" where name="conan"';
//delete
conn.query(deleteSQL, function (err0, res0) {
if (err0) logger.info(err0);
logger.info("DELETE Return ==> ");
logger.info(res0);
//insert
conn.query(insertSQL, function (err1, res1) {
if (err1) logger.info(err1);
logger.info("INSERT Return ==> ");
logger.info(res1);
//query
conn.query(selectSQL, function (err2, rows) {
if (err2) logger.info(err2);
logger.info("SELECT ==> ");
for (var i in rows) {
logger.info(rows[i]);
}
//update
conn.query(updateSQL, function (err3, res3) {
if (err3) logger.info(err3);
logger.info("UPDATE Return ==> ");
logger.info(res3);
//query
conn.query(selectSQL, function (err4, rows2) {
if (err4) logger.info(err4);
logger.info("SELECT ==> ");
for (var i in rows2) {
logger.info(rows2[i]);
}
});
});
});
});
});
//conn.end();