簡體   English   中英

NodeJS:從多語句 MySQL 查詢的結果中獲取值

[英]NodeJS: Getting the values from the result of a multiple statement MySQL query

我正在使用 Node.js 中的多語句查詢從數據庫中獲取數據。

我的查詢結果如下:

  [ [ RowDataPacket {
      name: 'Jericho',
      country: 'Canada',
      sex: 'Male',
      age: 12 } ],
  [ RowDataPacket {
      interpretation: 'a complex situation' } ],
  [ RowDataPacket {
      team: 'The Horses',
      colour: 'Purple' } ],
  [ RowDataPacket {
      start_day: 'Monday',
      end_day: 'Friday' } ] ]

我試圖從第四個RowDataPacket中獲取start_dayend_day值,以便我可以用破折號加入它們(例如周一至周五)。 我有以下代碼:

var days = rows[3]; //rows is the result of the query
console.log(days.start_day);
console.log(days.end_day);

但是 console.log() 的結果如下:

undefined
undefined

我不確定為什么start_dayend_day值被打印為undefined 任何見解都值得贊賞。

RowDataPacket 是構造函數 function,它創建了一個 object,看起來像this new RowDataPacket(start_day, end_day)

您可以使用 [0], 0th index 訪問它

var days = rows[3];
console.log(days[0].start_day);
console.log(days[0].end_day);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM