S
S
SergOdinokiy2019-11-24 12:54:26
Node.js
SergOdinokiy, 2019-11-24 12:54:26

Request to MySQL node.js?

Why does the function return an empty query? I understand that MySQL does not keep up with JS and an empty request comes in? Then how to get rid of it and get it not empty? How to write a function correctly?

function user(val) {
    var sss='';
    const connection = mysql.createConnection({
        database: 'base',
        host: "localhost",
        user: "root",
        password: ""
    });

    connection.query("SELECT * FROM `user` WHERE `uid`="+val+"",
        function(err, results) {
            console.log(results); //Тут все пришло!!!
            console.log(err);
            sss =results;
        });
    connection.end();
    return sss;
}

console.info(user(31)); //Тут пусто!!!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question