Sono nuovo nel nodo js, ora sto cercando di impostare un valore di ritorno della query select in mysql usando il nodo js .... Sto usando node-mysql pacchetto ...non può restituire un valore di query select usando mysql e node js
codice di esempio
var mysql = require('mysql');
var connection = mysql.createConnection({
host : "localhost",
user : "root",
password: "root123",
database: "testdb"
});
var retValue = undefined;
var query = connection.query('SELECT * FROM tblData;');
query
.on('error', function(err) {
// Handle error, an 'end' event will be emitted after this as well
})
.on('fields', function(fields) {
// the field packets for the rows to follow
})
.on('result', function(row) {
// Pausing the connnection is useful if your processing involves I/O
connection.pause();
processRow(row, function() {
retValue = row;
});
})
.on('end', function(row) {
});
connection.end();
function processRow(rows)
{
retValue = rows;
}
console.log(retValue);
retValue
è sempre indefinito. So che è una chiamata asincrona. Qualcuno mi dice come impostare il valore per questa variabile.
Grazie Deepak
Perché si desidera assegnare 'retValue' in' processRow' e nella sua richiamata? – Lewis
appena provato .... ma non riesco a impostare il risultato su quella variabile .... –
http://stackoverflow.com/questions/5964988/how-to-get-the-results-from-nodejs-using -mysql-package possibile aiuto – vanadium23