Hi there,

is there anybody who can help me? I think I have a asynchronous data 
problem:

My Code ( I made 3 approaches) 


var http = require('http');

var work = require('timetrack');

var mysql = require('mysql');

var qs = require('querystring');

var sync = require('synchronize')


function getonevalue(statement) //approach1

console.log('Im getonevalue');

var connection = mysql.createConnection({

  host:     '127.0.0.1',

  user:     'root',

  password: '',

  database: '****'

});

connection.connect();

debugger;

console.log('Running SQL: ' + statement);

var globalrows = connection.query(statement);

console.log('Statement ausgeführt');

console.log(globalrows[0].username));

//connection.query(statement, function(err, rows, fields) {

  //if (err) throw err;

  //globalrows = rows;

  //console.log('The solution is: ', rows[0].username);

//))});

console.log('returning ', globalrows[0].username));

return globalrows[0].username);

connection.end;


}


function getonevalue3(statement) //approach2

{

console.log('Im getonevalue');

var connection = mysql.createConnection({

  host:     '127.0.0.1',

  user:     'root',

  password: '',

  database: '****'

});

connection.connect();

debugger;

console.log('Running SQL: ' + statement);

connection.query(statement, function(err, result)

{

console.log('Statement ausgeführt');

console.log(result.rows[0].username);

return result.rows[0].username;

});


}



function getonevalue2 (statement)  //approach3

{

var connection = mysql.createConnection({

  host:     '127.0.0.1',

  user:     'root',

  password: '',

  database: '****'

});

connection.connect();

console.log('Running SQL: ' + statement);

connection.query

(statement,1, 

function results(err, rows) 

{

if (err) throw err;

console.log('Gelesener Wert: ');

console.log(rows[0].username);

return(rows[0].username); 

}

)

connection.end;

};


I called them via e.g.


var myreturn = mysqlhandler.getonevalue3("Select username from tbluser 
where username = '" + username + "'");

console.log('checkuser returnvalue:');

console.log(myreturn);)


What I get is:


Im getonevalue

Running SQL: Select username from tbluser where username = 'janos'

checkuser returnvalue:

undefined

Statement ausgeführt


The only thing I want is a synchron function which delivers one value from 
a mysql db!


1000 thanks in advance!

Janos



-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/203f8d54-6b14-4229-b3dd-e052026766e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to