Reputation: 87
At one point I was trying to use MySQL for my Nodejs project. No matter what I did it wouldn't perform the SELECT operation correctly or would bug out and not work. I have since tried using FS but I realized the overhead is going to be too much and Firestore is going to be far too complicated. Here is a quick snip of my code - it crashes saying "TypeError: Cannot read property 'flag' of undefined" (flag is in the database, ID and Flag are both fields in the database)
Am I misusing this and how can I fix it? (I might end up needing more help with debugging if it continues to not write to the database or read from it properly)
con.query(`SELECT * FROM pedodb WHERE ID = ?`, [msg.author.id],
function (err, result, fields) {
//callback(null, rows, fields);
console.log("Query Initiated")
if (ageCheck(msg.content.toLowerCase(), "8", "15")) {
if (result.flag in {
1: "P",
2: "S",
3: "YA",
4: "A"
}) {
}
}
})
Upvotes: 0
Views: 99
Reputation: 9706
You should check if (err) { console.log(err); return; }
as a first line in your callback function. Could be the table doesn't exist.
Also, result is an array, so, you should check if result.length > 0
and use result[0].flag
, should such column exist in the table.
Upvotes: 1