Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript MYSQL |语法错误,尽管所有内容都正确编写_Javascript_Mysql_Node.js_Discord.js - Fatal编程技术网

Javascript MYSQL |语法错误,尽管所有内容都正确编写

Javascript MYSQL |语法错误,尽管所有内容都正确编写,javascript,mysql,node.js,discord.js,Javascript,Mysql,Node.js,Discord.js,我正在尝试使用NodeJS从MySql数据库读取数据。我实际上已经在另一个文件中做了,在那里它工作得很好! 我正在使用: console.log('GuildId: ' + guildId); let MemberCountChannel = new Map();{ connection.promise().query( guildId, `SELECT memberCountId FROM GuildConfigurable WHERE guildId = '${guildId}'

我正在尝试使用NodeJS从MySql数据库读取数据。我实际上已经在另一个文件中做了,在那里它工作得很好! 我正在使用:

console.log('GuildId: ' + guildId);

let MemberCountChannel = new Map();{

connection.promise().query( guildId,
    `SELECT memberCountId FROM GuildConfigurable WHERE guildId = '${guildId}'`
).then(result => {
    MemberCountChannel.set(guildId, result[0][0].memberCountId);
    MemberCountChannelId = MemberCountChannel.get(guildId);

console.log(MemberCountChannelId);
我知道Guidid是对的,因为它在我代码的开头就记录了它。 执行该代码时,我得到以下信息:

GuildId: 776182101337833474
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '776182101337833474' at line 1
    at PromiseConnection.query (/home/ubuntu/discord-bot-v2/node_modules/mysql2/promise.js:92:22)
    at Timeout._onTimeout (/home/ubuntu/discord-bot-v2/counters/member-counter.js:20:26)
    at listOnTimeout (node:internal/timers:556:17)
    at processTimers (node:internal/timers:499:7) {
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlState: '42000',
  sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '776182101337833474' at line 1"
}
我已尝试将“${guildId}”更改为仅公会Id:

console.log('GuildId: ' + guildId);

    let MemberCountChannel = new Map();{

    connection.promise().query( guildId,
        `SELECT memberCountId FROM GuildConfigurable WHERE guildId = '776182101337833474'`
    ).then(result => {
        MemberCountChannel.set(guildId, result[0][0].memberCountId);
        MemberCountChannelId = MemberCountChannel.get(guildId);

    console.log(MemberCountChannelId);
但是使用这个,我得到了相同的输出。我的数据库表如下所示:

mysql> SELECT * FROM GuildConfigurable;
+--------------------+-----------+----------------+---------------+----------------+
| guildId            | cmdPrefix | radioChannelId | memberCountId | AutoStartRadio |
+--------------------+-----------+----------------+---------------+----------------+
| 776182101337833474 | <         | N/A            | N/A           | N              |
| 791351561182904381 | <         | N/A            | N/A           | N              |
| 804867729404067904 | <         | N/A            | N/A           | N              |
+--------------------+-----------+----------------+---------------+----------------+
3 rows in set (0.00 sec)
我得到了我需要的输出:

SELECT memberCountId FROM GuildConfigurable WHERE guildId = 776182101337833474;
+---------------+
| memberCountId |
+---------------+
| N/A           |
+---------------+
1 row in set (0.01 sec)
知道我为什么会犯这个错误吗?我很确定没有语法错误

EDIT:
我已经完全重新安装了mysql2和mysql服务器,并且在另一个文件中使用了几乎相同的脚本来获取cmdPrefix:

var guildId = message.guild.id; 
    getMemberCount(client, guildId);

    let guildCommandPrefix = new Map();
    connection.promise().query(
        `SELECT cmdPrefix FROM GuildConfigurable WHERE guildId = '${message.guild.id}'`
    ).then(result => {
        guildCommandPrefix.set(message.guild.id, result[0][0].cmdPrefix);
        prefix = guildCommandPrefix.get(message.guild.id);

这个很好用…

尝试在SELECT语句的末尾添加分号:

connection.promise().query( guildId,
        `SELECT memberCountId FROM GuildConfigurable WHERE guildId = '776182101337833474';`
    ).then(result => {
        MemberCountChannel.set(guildId, result[0][0].memberCountId);
        MemberCountChannelId = MemberCountChannel.get(guildId);

您确定第一个参数应该是ID吗?是否应该是查询?

没有任何更改。。。它甚至没有在错误消息中显示分号……我建议记录查询,然后在Adminer或PhpMyAdmin之类的工具下复制粘贴。我同意,第一个参数应该是queryow。。。是的,你们是对的…:D
connection.promise().query( guildId,
        `SELECT memberCountId FROM GuildConfigurable WHERE guildId = '776182101337833474';`
    ).then(result => {
        MemberCountChannel.set(guildId, result[0][0].memberCountId);
        MemberCountChannelId = MemberCountChannel.get(guildId);
connection.promise().query( guildId,
    `SELECT memberCountId FROM GuildConfigurable WHERE guildId = '${guildId}'`
)