-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.js
More file actions
38 lines (34 loc) · 974 Bytes
/
Copy pathmysql.js
File metadata and controls
38 lines (34 loc) · 974 Bytes
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
// get the client
const mysql = require('mysql2');
// create the connection to database
const connection = mysql.createConnection({
host: '192.168.3.25',
user: 'wanglei',
password: 'mnbvcxz@123',
database: 'web-node',
});
connection.on('error', (err) => {
console.log('error emited', err.message);
});
console.log(new Date().toLocaleString());
// simple query
connection.query(
'SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45',
function (err, results, fields) {
console.log(results); // results contains rows returned by server
console.log(fields); // fields contains extra meta data about results, if available
}
);
// with placeholder
connection.query(
'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
['Page', 45],
function (err, results) {
console.log(results);
}
);
// with placeholder
connection.query('show TABLES', [], function (err, results, fields) {
console.log(results, typeof fields);
});
console.log('bottom runing');