【问题标题】:Getting schema info in mysql query在 mysql 查询中获取模式信息
【发布时间】:2019-07-14 16:12:36
【问题描述】:

我在mysql数据库中有一张表,里面有3条记录。该表有 11 列。我正在使用mysql2 进行查询; 我的查询是:

let mylist=[];
     mylist = await  pool.query( "SELECT * FROM mytable WHERE username = ?", usrname);

我没有得到一个包含三个对象的数组,而是得到一个内部有两个数组的数组。在第一个数组中有我想要获取的三个记录。 但在第二个数组中,我得到如下结果:

1: Array(11)
0:
characterSet: 63
columnLength: 8
columnType: 3
decimals: 0
encoding: "binary"
flags: 16903
name: "id"
_buf: {type: "Buffer", data: Array(886)}
_catalogLength: 3
_catalogStart: 10
_clientEncoding: "utf8"
_orgNameLength: 2
_orgNameStart: 37
_orgTableLength: 7
_orgTableStart: 26
_schemaLength: 3
_schemaStart: 14
_tableLength: 7
_tableStart: 18
__proto__: Object
1:
characterSet: 224
columnLength: 56
columnType: 253
decimals: 0
encoding: "utf8"
flags: 20485
name: "mnm"
_buf: {type: "Buffer", data: Array(886)}
_catalogLength: 3
_catalogStart: 57
_clientEncoding: "utf8"
_orgNameLength: 3
_orgNameStart: 85
_orgTableLength: 7
_orgTableStart: 73
_schemaLength: 3
_schemaStart: 61
_tableLength: 7
_tableStart: 65
__proto__: Object
2:
characterSet: 224
columnLength: 48
columnType: 253
decimals: 0
encoding: "utf8"
flags: 20489
etc...
etc....

我想知道为什么我在第二个数组对象的查询结果中得到了我不想要的所有列的详细信息。

【问题讨论】:

    标签: node.js mysql2


    【解决方案1】:

    我发现它是 issuenode-mysql2 。解决方法是(在问题讨论中给出)像

    一样查询
    const [rows] = await conn.query(sql);
    

    或者像这样

    db.query(query).then(function(response) {
        var data = response[0];
        // use data
    });
    

    【讨论】:

      猜你喜欢
      • 2012-07-29
      • 2012-06-12
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-19
      • 1970-01-01
      相关资源
      最近更新 更多