On May 21, 2014, at 08:22, Janos wrote:

> 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

[snip]

> function getonevalue3(statement) //approach2

[snip]

> function getonevalue2 (statement)  //approach3

[snip]

> I called them via e.g.
> 
> var myreturn = mysqlhandler.getonevalue3("Select username from tbluser where 
> username = '" + username + "'");
> console.log('checkuser returnvalue:');
> 
> console.log(myreturn);)

[snip]

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

This can't work. The database returns the result asynchronously, so you cannot 
write a function that interacts with it synchronously.

Your function signature needs to be:

function getonevalue(statement, callback)

And you will write that function to call the callback once it has gotten the 
value from the database. So you will call it like this:

mysqlhandler.getonevalue("Select username from tbluser where username = '" + 
username + "'", function(err, myreturn) {
  if (err) {
    console.error(err);
    return;
  }
  console.log(myreturn));
});

And then there are other problems, such as you shouldn't be creating an SQL 
string by concatenating user-supplied values such as username, but that's a 
different topic.

-- 
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/527E912A-40E8-4027-AF87-5BF3D6FA4262%40ryandesign.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to