Hello everyone,

I am trying to test nodejs with mysql, I think due to its non-blocking
nature. I have a difficult time to add the query result into a output
buffer (var output in following code). Can anybody point me some way?

Thanks,
Alex

  var mysql      = require('db-mysql');
  var db = new mysql.Database({
    hostname     : 'localhost',
    user     : 'test_user',
    password : 'test_passwd',
    database : 'test_db',
    charset  : 'utf8',
  })
  db.connect();

  http.Server(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    var output = '<html>\n<head>\n<title>Speed test</title>\n</head>
\n<body>\n';

    for (var i = 0; i < 1000; i++) {
      db.query('SELECT uid, username FROM users WHERE uid = ' +
i).execute(function(err, rows) {
        if(rows.length > 0) {
          output += (rows[0].uid + ' : ' + rows[0].username + '<br />
\n');
          //console.log(output);
        }
      });
    }

    output += '</body>\n</html>';
    res.end(output);

  }).listen(8000);

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
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 post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to