-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathmysql2tst.js
More file actions
28 lines (25 loc) · 803 Bytes
/
mysql2tst.js
File metadata and controls
28 lines (25 loc) · 803 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
// Adapted from the documentation of https://github.com/sidorares/node-mysql2,
// which is licensed under the MIT license; see file node-mysql2-License.
const mysql = require('mysql2');
// create the connection to database
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'test'
});
// 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);
}
);