var mysql = require(‘mysql‘); var pool = mysql.createPool({ host: ‘localhost‘, user: ‘root‘, password: root, database: demo, port: 3306 }); function MySQLHelper() { }; function QuerySQL(querysql, callback) { pool.getConnection(function (err, conn) { //if (err) console.log("POOL ==> " + err); if (err) { conn.release(); return callback(err); } conn.query(querysql, function (err2, rows) { //if (err) console.log(err); if (err2) { conn.release(); return callback(err2); } //console.log("SELECT ==> "); conn.release(); callback(err2,rows); }); }); }; function ExecuteSQL(executesql, callback) { pool.getConnection(function (err, conn) { //if (err) console.log("POOL ==> " + err); if (err) { conn.release(); return callback(err); } conn.query(executesql, function (err2, res) { //if (err) console.log(err); if (err2) { conn.release(); return callback(err2); } //console.log("SELECT ==> "); conn.release(); callback(err2,res.affectedRows); }); }); }; MySQLHelper.prototype.ExecuteSQL = ExecuteSQL; MySQLHelper.prototype.QuerySQL = QuerySQL; module.exports = MySQLHelper;
时间: 2024-10-10 07:27:39