2

I try to get the number of found rows out of a mysql query with a limitation. Google gave me the hint with the SQL_CALC_FOUND_ROWS function.

I also get the right result in the "RowDataPackage".

RowDataPacket { 'FOUND_ROWS()': 5 }

But when i try to parse the result with

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

I only get the result "undefined". What am i doing wrong?

itscaN
  • 23
  • 6
  • Possible duplicate of [How to access object properties containing special characters?](http://stackoverflow.com/questions/12953704/how-to-access-object-properties-containing-special-characters) – Tomalak Mar 07 '17 at 07:39
  • `rows[0].FOUND_ROWS()` is a function call, can you alias your query to return proper column name? – slier Mar 07 '17 at 07:40
  • 2
    This is not a node.js question and not a MySQL question. This is a basic JavaScript syntax question. – Tomalak Mar 07 '17 at 07:40

1 Answers1

1

Try this:

console.log(rows[0]["FOUND_ROWS()"]);

Your current call is being interpreted as a function call. Instead, use square brackets to escape the key name in your JSON.

As @Tomalak mentioned, your question doesn't have too much to do with MySQL, rather just regular JavaScript.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360