0

I am using msnodesqlv8 to query my SQL database in Node.JS

I am calling this function, which returns undefined for the variable:

function check_db(){
    const query = "my sql query";
    sql.query(connectionString, query, (err, rows) => {
        console.log(rows)
    });
return rows //obviously this returns undefined when check_db() is called
}

I have also tried the following method, which hasn't worked

function check_db(){
        var a;
        const query = "my sql query";
        sql.query(connectionString, query, (err, rows) => {
            console.log(rows)
            a = rows
        });
    return a //also returns undefined
   }

Any help is massively appreciated

EcSync
  • 842
  • 1
  • 6
  • 20
  • And [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](https://stackoverflow.com/q/23667086/4642212). – Sebastian Simon Oct 02 '19 at 11:56
  • @SebastianSimon I don't want to use promises - I can never get them to work very well. There must be cleaner solution – EcSync Oct 02 '19 at 11:57

0 Answers0