RowDataPacket返回未定义的值

时间:2017-07-16 08:30:18

标签: mysql node.js stored-procedures

我有一个存储过程要插入到db中,并在插入后将订单ID返回到控制台。

这是我的存储过程

CREATE PROCEDURE create_old_user_order(
IN p_userid      int(11),
IN p_userfname   varchar(50),
IN p_userlname   varchar(50),
IN p_phone       varchar(20),
IN p_item        int(11),
IN p_item_qty    int(11))
BEGIN
INSERT INTO user_order(customer_id,
                   first_name,
                   last_name,
                   phone_numb,
                   order_item,
                   order_quantity)
    VALUES (p_userid,
            p_userfname,
            p_userlname,
            p_phone,
            p_item,
            p_item_qty);

  SET @LAST_id = LAST_INSERT_ID();

  SELECT @LAST_id AS `booking_id`;
  END;

从Node.js Express应用程序调用该过程很好。

     console.log(results)

显示了这个

       [ [ RowDataPacket { booking_id: 15646747643 } ],
       OkPacket {
        fieldCount: 0,
        affectedRows: 0,
         insertId: 0,
         serverStatus: 2,
          warningCount: 0,
            message: '',
           protocol41: true,
             changedRows: 0 } ]

       console.log(results[0]) 

显示了这一点:

      [ RowDataPacket { booking_id: 15646747643 } ]

这样做

       console.log(results[0].booking_id)

我得到了

         Undefined. 

请HELPPPP

1 个答案:

答案 0 :(得分:0)

修好了。应该这样访问它

 results[0][0].booking_id