2
mysqlconnection.query("SELECT userID FROM users_session WHERE userSessionID = '" + SESSION_ID_ESCAPED + "'", function SelectCb (err, rows) {
if (err) {
    throw err;
}
else {
    console.log(rows[0]);
}

How do I turn row[0] into a string so that the browser can view it?

The console tells me rows[0] = {userID: 2} // This is [object Object] in any sort of transfer.

I used , var TheID = rows[0].toString // TheID is now undefined when console.log'd or sent out.

Himanshu
  • 31,810
  • 31
  • 111
  • 133
Indie
  • 23
  • 1
  • 6
  • Does this answer your question? [Why does \`Object.prototype.toString\` always return \`\[object \*\]\`?](https://stackoverflow.com/questions/13151809/why-does-object-prototype-tostring-always-return-object) – Vasyl Moskalov May 18 '22 at 10:23

2 Answers2

7

try:

var TheID = rows[0]['userID'].toString();
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • Are you sure that shouldn't be `rows[0]['userID'].toString();`? Or equivalently, `rows[0].userID.toString();`. – aroth Aug 24 '12 at 05:34
0

try this..

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

you will get the userID.

Himanshu
  • 31,810
  • 31
  • 111
  • 133
Rakesh
  • 353
  • 1
  • 4
  • 21