title: Store a return of a callback function in a global variable (Node.JS + Mysql)
body: <p>This code (of node.js + mysql) works correctly, but I need to store the value of <code>mot_rech</code> in a global string variable in order to do some operations. I have tried several methods, but they didn't work. I need your help.</p>
  
  <p>Code: </p>
  
  <pre><code>var func = function(callback) {
    connection.connect;
  
    var sSQL = 'SELECT mot FROM dictionnaire ORDER BY RAND() LIMIT 1';
  
    connection.query(sSQL, function(err,rows,fields) {
      if (err != null) {
        console.log('Query error n° :' + err)
      } else {
        {  
          t = JSON.stringify(rows[0].mot);
          callback(t);
        }
      }
    });
  }
  
  func(function(mot_rech){
    console.log("votre mot = " + mot_rech)
  });
  </code></pre>