Vietnam

    Nodejs.vn

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Groups
    • Search

    XINGIUP: GET DATA TỪ API VỀ MYSQL LỖI: underfined

    Hỏi Đáp
    0
    10
    661
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      Game4u last edited by

      alt text

      1 Reply Last reply Reply Quote 0
      • G
        Game4u last edited by

             var connection = mysql.createConnection({
            host: 'localhost',
            port: 3306,
            user: 'admin',
            password: '',
            database: 'DATAAPI'
        });
        

        connection.connect(function(error){
        if(!!error){
        console.log('Error');
        }else{
        console.log('Connected to the database!');
        }
        });
        var scrape = JSON.stringify(output, null, 4);
        //console.log(scrape);
        console.log(output);

           var query = connection.query("INSERT INTO TESTDATA (title, date, month, venue, link) VALUES ('" + output.title + "', '" + output.date + "', '" + output.month + "', '" + output.venue + "', '" + output.link + "');", scrape, function(err, result) {
         if(err) throw err;
         console.log('data inserted');
        

        });

        1 Reply Last reply Reply Quote 0
        • Nguyen Hien
          Nguyen Hien last edited by

          Bạn chuyển qua dùng literal string template cho dễ viết https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals.
          Với bạn có cái log query debug không ?

          Sent from Rodgers Zone!!!

          1 Reply Last reply Reply Quote 0
          • G
            Game4u last edited by

            0_1526016368319_image.png

            Nguyen Hien 1 Reply Last reply Reply Quote 0
            • G
              Game4u last edited by

              đây là log trả về dữ liệu của "output" ạ , code dài quá e k viết được quá 150 kí tự
              bác giúp e với

              1 Reply Last reply Reply Quote 0
              • Linh Thỏ
                Linh Thỏ last edited by

                Mình cũng có lỗi giống bạn , quan tâm .

                1 Reply Last reply Reply Quote 0
                • Nguyen Hien
                  Nguyen Hien @Game4u last edited by

                  @Game4u Sao server auto restart thế ?. Thế thì data store memory của bạn sao access vào được ??
                  P/S: Mình làm frontend thì hot loading. Chứ còn backend mình viết xong rồi test. Chứ k dùng hot loading

                  Sent from Rodgers Zone!!!

                  1 Reply Last reply Reply Quote 0
                  • G
                    Game4u last edited by

                    sau khi e tắt nodemon

                    0_1526099349011_image.png

                    Nguyen Hien 2 Replies Last reply Reply Quote 0
                    • Nguyen Hien
                      Nguyen Hien @Game4u last edited by Nguyen Hien

                      @Game4u Bạn cần lấy thông tin gì mà ko lấy được ?.
                      Ví dụ title: output.events[i].title, date: output.events[i].date

                      Sent from Rodgers Zone!!!

                      1 Reply Last reply Reply Quote 0
                      • Nguyen Hien
                        Nguyen Hien @Game4u last edited by

                        @Game4u Bạn thử move phần code insert vào chỗ console.log('DB connected') xem. Rồi test coi DB có chưa. Có rồi hẵng thực hiện lệnh lấy ra.

                        Sent from Rodgers Zone!!!

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post