Every time I get Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘by, user, reason, active) VALUES (5, 663403380223377400, 793061601288388600, 274’.
x
connection.query('INSERT INTO modlogs (logtypeid, textchannel, message, by, user, reason, active) VALUES (?, ?, ?, ?, ?, ?, ?)', [5, parseInt(message.channel.id), parseInt(message.id), parseInt(message.author.id), parseInt(mentionedMember.id), reason, 1], (error, results) => {
if (error) console.log('MariaDB Error: ' + error)
})
Did I miss something in the query?
MariaDB version: 10.1.47
Kind Regards,
Corné
Advertisement
Answer
by
is a reserved word in MySQL and in MariaDB, so you need to quote it:
INSERT INTO modlogs (logtypeid, textchannel, message, `by`, `user`, reason, active)
VALUES (?, ?, ?, ?, ?, ?, ?)
A better idea would be to use an identifier that does not conflict with a reserved word (or keyword). There are plenty of words in English, and just a few hundred are SQL keywords.
Note that I also quoted user
: it is not a reserved word, but a language keyword, but it is still a good practice to quote it.