常用sql
emer 发布于 2018-11-23 10:26 2367 次阅读
var express = require('express'); var router = express.Router(); var cookieParser = require('cookie-parser'); var session = require('cookie-session'); var md5=require("md5"); var mysql = require('mysql'); var sql1=require("../../libs/sql"); var session = require('express-session');
let sql={ selectSql(sql,dataBase) { var promise = new Promise(function(resolve,reject) { var result = null; var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '' }); connection.connect(); connection.query(dataBase); connection.query(sql, function (err, results, fields) { if (err) { console.log("err"); reject({status:"400",err:err,msg:"无数据"}); }else { resolve({status:"200",data:results,msg:"成功!"}); } } ); connection.end(); }) return promise; }, }; module.exports=sql;