//db.js module
var mysql = require("mysql");
var insights;

function setup(client) {
	insights = client;
}

function getVideos(term, callback) {


	var con;

	con = mysql.createConnection({
			host: "localhost",
			user: "seattle",
			password: "P@ssw0rd1",
			database: "meetup"
		});

	con.connect(function(err){
		if(err){
			console.log('Error connecting to Db');
			return;
		}

		insights.trackEvent("mysql.connection");

		insights.trackEvent("mysql.query", {term: term});

		con.query(
			'SELECT Title,URL,PlayerURL FROM meetup.AllChannel9Videos WHERE Tags like \'%' + term + '%\' order by TotalViewCount DESC LIMIT 10',
			function(err,rows){
				con.end();
				if(err) throw err;
				callback(rows);
			}
		);		
	});
}

function endConnection() {
	try {
		con.end(function(err) {});
		
	} catch (error) {
		console.log("Error closing connection");	
	}
}
	

module.exports = {
	getVideos: getVideos,
	setup: setup
};


@@ -474,16 +474,53 @@
 erm%7D);%0A%0A
+%09%09var termvalue = '%25' + term + '%25';%0A%0A
 %09%09con.qu
@@ -605,26 +605,9 @@
 ike 
-%5C'%25' + term + '%25%5C'
+?
  ord
@@ -642,16 +642,29 @@
 MIT 10',
+ %5Btermvalue%5D,
 %0A%09%09%09func

move DB to use placeholder