Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.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不';t在结果对象中返回消息_Javascript_Mysql_Node.js - Fatal编程技术网

javascript/mysql不';t在结果对象中返回消息

javascript/mysql不';t在结果对象中返回消息,javascript,mysql,node.js,Javascript,Mysql,Node.js,我想创建mysql表,如果它们还没有在我的mysql数据库中创建的话。 代码本身正在工作,但是如果创建了一个新表,或者已经存在一个同名表,我想输出一条消息 con.query("CREATE TABLE IF NOT EXISTS " + guild + " (id INT AUTO_INCREMENT PRIMARY KEY, userid INT, username CHAR(50), messages INT)", function (err, result) {

我想创建mysql表,如果它们还没有在我的mysql数据库中创建的话。 代码本身正在工作,但是如果创建了一个新表,或者已经存在一个同名表,我想输出一条消息

con.query("CREATE TABLE IF NOT EXISTS " + guild + " (id INT AUTO_INCREMENT PRIMARY KEY, userid INT, username CHAR(50), messages INT)", function (err, result) {
            if (err) throw err    
            console.log(result.message)
        })
但是,如果我正在打印result.message,它总是空的,即使我自己在mysql中创建数据库时,我会收到一条类似于“受影响的0行”的返回消息,如果它有效,或者“受影响的0行,1条警告:1050表“test”已经存在”

因此,我的问题是,是否有任何方法可以检查是否通过返回对象成功创建了表,或者是否有另一种不涉及多个sql查询的简单方法

请澄清:

当打印结果时,如果没有表“test”已经存在,则如下所示:

OkPacket {
  fieldCount: 0,
  affectedRows: 0,
  insertId: 0,
  serverStatus: 2,
  warningCount: 0,
  message: '',
  protocol41: true,
  changedRows: 0
}
OkPacket {
  fieldCount: 0,
  affectedRows: 0,
  insertId: 0,
  serverStatus: 2,
  warningCount: 1,
  message: '',
  protocol41: true,
  changedRows: 0
}
当已经存在名为“test”的表时,它看起来如下所示:

OkPacket {
  fieldCount: 0,
  affectedRows: 0,
  insertId: 0,
  serverStatus: 2,
  warningCount: 0,
  message: '',
  protocol41: true,
  changedRows: 0
}
OkPacket {
  fieldCount: 0,
  affectedRows: 0,
  insertId: 0,
  serverStatus: 2,
  warningCount: 1,
  message: '',
  protocol41: true,
  changedRows: 0
}

属性“warningCount”不表示警告,我无法区分警告,它也可能是由mysql正在输出的其他警告引起的,因此检查该属性将不起作用。

结果具有可用于显示警告的属性:

console.log(result.affectedRows + " row(s) affected");
console.log(result.warningCount + " warning(s)");
console.log(result.message);

如果表“test”不存在,则在创建该表时,打印“result”如下所示:``OkPacket{fieldCount:0,affectedRows:0,insertId:0,serverStatus:2,warningCount:0,message:'',protocol41:true,changedRows:0}``但如果“test”已经在我的数据库中,则“result”如下所示:``OkPacket{fieldCount:0,affectedRows:0,insertId:0,serverStatus:2,warningCount:1,消息:“”,协议41:true,changedRows:0}“``但是warningCount中的更改也可能是由mysql输出的其他错误引起的……因此我不知道如何区分错误消息、表已经创建和另一个错误。。。