how to run a query SQL in node.js mysql -
i have syntax problem in module, fail sql query.
i initialize module database in file.js, responds console.log 'connected database', sends data module in database.newdata(data), when enters in runquery nothing happens, no errors or result, nothing!
i in runquery if query ok , if this, think happens there error in logic of node, idea connect database , use runquery run query pass.
file.js
var db = require('./modules/database'); var database = new db(); database.newdata(data);
database.js
var mysql = require('mysql'), queries = require('./queries'), connection; var db = function(){ var db_config = { host: 'localhost', user: 'diegoug', password: 'qwertyuiop', database: 'test' }; connection = mysql.createconnection(db_config); connection.connect(function(err) { if(err) { console.log('error when connecting database:', err); } console.log('connected database'); }); } db.prototype.runquery = function(query,data,cb){ // here not pass nothing connection.query( query, data, function(err, results){ debugger; if (err)throw err; cb(results); } ); // here if query written , if is, happens it's not running in connection } db.prototype.newdata = function(data){ var query = queries.sqlnewdata, data = [data]; var res = this.runquery(query,data); console.log(res); } module.exports = db;
Comments
Post a Comment