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?

3
  • Possible duplicate of How to access object properties containing special characters? Commented Mar 7, 2017 at 7:39
  • rows[0].FOUND_ROWS() is a function call, can you alias your query to return proper column name? Commented Mar 7, 2017 at 7:40
  • 2
    This is not a node.js question and not a MySQL question. This is a basic JavaScript syntax question. Commented Mar 7, 2017 at 7:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.