I'm currently working with JS, DiscordJS and MySQL and trying to get some data from the table which usually always worked fine. But I'm struggling with a MySQL SELECT query because it doesn't checks if the value in the table is exectly the same as it is searching for. The end of the Discord ID is different then the one it's searching for.
Code:
let query = `SELECT * FROM accounts WHERE DiscordID = ${interaction.member.id}`;
console.log(`QUERY: ` + query);
MySQL.Connect()
.then((connection) => {
MySQL.Query(connection, query)
.then((results) => {
if (results == '') {
console.log('[RESULTS = 0]');
console.log(results);
} else {
console.log('[RESULTS > 0]');
console.log(results);
}
})
.catch((error) => {
console.log(error);
})
.finally(() => {
connection.end();
});
})
.catch((error) => {
console.log(error);
});
Result:
QUERY: SELECT * FROM accounts WHERE DiscordID = 466934561738326016
RESULT:
ID: 1,
Username: 'Test',
Password: 'Test',
DiscordID: '466934561738326022'
MySQL schema:
CREATE TABLE IF NOT EXISTS `accounts` (
`ID` INT NOT NULL AUTO_INCREMENT,
`Username` VARCHAR(255) NOT NULL,
`Password` VARCHAR(255) NOT NULL,
`DiscordID` VARCHAR(100) NOT NULL,
PRIMARY KEY (`ID`));