123456789101112131415161718192021222324252627 |
- const mysql=require("mysql");
- const pool = mysql.createPool({
- host: 'db.1473.cn',
- user: 'root',
- password: 'usestudio-1',
- database: 'weibo'
- });
-
- const query=function(sql,options,callback){
- pool.getConnection(function(err,conn){
- if(err){
- console.log(err)
- callback(err,null,null);
- }else{
- conn.query(sql,options,function(err,results,fields){
- //释放连接
- conn.release();
- //事件驱动回调
- callback(err,results,fields);
- });
- }
- });
- };
-
- module.exports = query;
|