code
const mysql = require("mysql")
class Database
{
constructor(){
this.connection = mysql.createConnection({
host: 'gz-cdb-82qen0rr.sql.tencentcdb.com',
user: 'root',
password: '12345678abc',
port: '63750',
database: 'test1',
});
this.connection.connect((err) => {
if (err) { console.log("连接失败") }
else { console.log("连接成功") }
})
}
getSqlData (sql, data) {
return new Promise((resolve, reject) => {
this.connection.query(sql, data, (error, result, fields) => {
if (error) {
reject(error)
} else {
resolve(result)
}
})
})
}
}
module.exports = Database;
const DataBase = require('./mysql')
const database = new DataBase()