Pcel:mysql - Using Mysql in Client Side


#1

Hi All,

I am trying to use the package : pcel:mysql, I am able to access the mysql data using the server side and I can print the data using the console.log, but it is not working in the client side. There is no documentation from where I can take some help.

It says connection is undefined. Can any one help me in this case.

 if (Meteor.isClient) {

Meteor.subscribe('playerScore');


Template.hello.helpers({

'data2': function(){
console.log(Meteor.call("mysqltestcall1"));
},

'data3': function(){

var connection = mysql.createConnection({
host     : 'localhost',
user     : 'root',
password : '',
database : 'leaderboard'
});


 connection.connect();


 connection.query('SELECT * FROM players', function(err, rows, fields) {
if (err) throw err;
 console.log(rows);
 //return rows;
     });

   }
   });

   }

if (Meteor.isServer) {

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '',
  database : 'leaderboard'
  });

connection.connect();


Meteor.methods({
'mysqltestcall1': function(){

connection.query('SELECT * FROM players', function(err, rows, fields) {
if (err) throw err;
console.log(rows);
return rows;
 });


}

});



 Meteor.publish('playerScore', function(name) {

connection.query('SELECT * FROM players', function(err, rows, fields) {
  if (err) throw err;

  return rows;
});

});

}