How to get a value from mysql query outside the query statement?

后端 未结 2 1754
抹茶落季
抹茶落季 2021-01-26 18:27

Here is the function see below console.log

function quo (value){
    value = connection.query(
       \'SELECT role from `roles` where `id` = 1\' , 
       fu         


        
2条回答
  •  执念已碎
    2021-01-26 19:05

    function quo (success){
        value = connection.query(
           'SELECT role from `roles` where `id` = 1' , 
           function (error, results, fields) {
               if (error) throw error;
               console.log('The role is: ', results[0].role);
               success (results[0].role);
           });
    }
    
    quo (function (role) {
       console.log(role);
       /* do something useful with the role that came back from the query */
    });
    

提交回复
热议问题