25 lines
512 B
JavaScript
Executable File
25 lines
512 B
JavaScript
Executable File
// { 服务器连接数据库(未启用) }
|
|
|
|
const mysql = require('mysql');
|
|
const client = mysql.createConnection({
|
|
host:"localhost",
|
|
user:"root",
|
|
password:"",
|
|
// database:"数据库名称"
|
|
})
|
|
|
|
/**
|
|
* query执行数据库语句的方法
|
|
*/
|
|
|
|
module.exports = function sqlFn(sql,arr,callback){
|
|
client.query(sql,arr,(error,result) => {
|
|
if(error){
|
|
console.log(error)
|
|
return;
|
|
}
|
|
callback(result) //回调函数
|
|
})
|
|
}
|
|
|