Skip to content Skip to sidebar Skip to footer

Node MySQL: Return A Value From A Column

I'm using mysql in a Node application, Discord bot. I want to select a value from a column but am having trouble in doing so. This is my code: let prefix; connection.query(`SELECT

Solution 1:

The console log event not firing would imply empty result set from the query. Although it looks like this isn't the exact code you are using, the parameter list to forEach looks wrong.

    (value => 
        prefix = value.prefix;
        console.log(value.prefix) // doesn't fire
    }

Try letting the sql engine include the variable value via sql parameters instead of using string interpolation. I mean something like:

connection.query('SELECT * FROM guilds WHERE guildid = ?',[message.guild.id], function(error, commands) { ...

https://www.sitepoint.com/using-node-mysql-javascript-client/

What is the value of message.guild.id?


Post a Comment for "Node MySQL: Return A Value From A Column"