0
if (command === "buy") {
  var query = `select piecoin from coin;` + `select cakecoin from coin;`;

  database.query(query, (err, rows, field) => {
    if (err) {
      console.log(err);
    } else {
      console.log(rows[0]);
    }
  });

Result: [ RowDataPacket { piecoin: 100 } ] If i change like this

else {
      console.log(rows[0].piecoin);
    }

Result: Undefined / I want to get Result data of field "100"

I can get result i want when i don't use multiple query like this

if (command === "buy") {
  var query = `select piecoin from coin;`;

  database.query(query, (err, rows, field) => {
    if (err) {
      console.log(err);
    } else {
      console.log(rows[0].piecoin);
    }
  });

Result: 100

I want get coin value and get user's money data then if buy a coin and decrease users'money

  • Take in consideration this question https://stackoverflow.com/questions/31979008/sql-two-select-statements-in-one-query to help you to use two `SELECT` statements on the same query. Or you can try this: `SELECT piecoin, cakecoin FROM coin` – Caio César P. Ricciuti Dec 01 '21 at 05:51

1 Answers1

0

Have you ever set multipleStatements option to true in mysql db option? You have to do this to enable multi-query.


const mysql = require('mysql');

mysql.createConnection({
    user: 'db user',
    host: 'db host',
    database: 'db name',
    password: 'db password',
    port: 'db port',
    // multi query on
    multipleStatements: true,
})

try this

devCrow
  • 88
  • 5