When trying to get all the rooms with the same app_id from my database im getting no results in Node but when I do exactly the same in phpmyadmin ,it works!
Query that works in phpmyadmin:
SELECT a.id FROM cc_app_rooms a JOIN cc_apps b ON a.app_id = b.id WHERE b.app_hash = "1234abc"
In Node the following does not work and logs for rows.affectedRows: "undefined"
function room_exists(app_hash, room) {
console.log(app_id + " " + room)
var rooms = [];
var sql = 'SELECT a.id FROM cc_app_rooms a JOIN cc_apps b ON a.app_id = b.id WHERE b.app_hash = ?';
con.query(sql, [app_hash], function(err, rows, fields) {
if (err) throw err;
console.log("ROWS: " + rows.affectedRows);
rows.forEach(function(row) {
rooms.push(row.id);
});
});
return rooms.includes(room);
}
And im calling the function like this:
room_exists(1, "1234abc")
Table cc_apps:
|id|_____app_hash______|
|1 |______1234abc______|
Table cc_app_rooms:
|id|____app_id____|
|1 |_____1________|
|2 |_____1________|
Im getting 2 results in phpmyadmin like expected, but the same does not seem to work in node? I know im missing something but im new to this.
The function logs the right values for room
and app_hash
and also no error is thrown.