Advertisement
jordman

Untitled

Mar 7th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mysql = require('mysql');
  2.  
  3. var pool = mysql.createPool({
  4.     connectionLimit: 5,
  5.     host: 'localhost',
  6.     user: 'root',
  7.     password: '',
  8.     database: 'final_project'
  9. });
  10.  
  11. exports.executeQuery = function (query, vals, callback) {
  12.     pool.getConnection(function (err, connection) {
  13.         if (err) {
  14.             connection.release();
  15.             callback(err, null);
  16.         }
  17.         connection.query(query, vals, function (err, rows, fields) {
  18.             connection.release();
  19.             if (!err) {
  20.                 callback(null, rows);
  21.             }
  22.         });
  23.         connection.on('error', function (err) {
  24.             callback(err, null);
  25.         });
  26.     });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement