// get the client
const mysql = require('mysql2');
// create the connection to database
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'test'
});
// simple query
connection.query(
'SELECT * FROM `user`',
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);
// }
// );
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)