sql >> Database teknologi >  >> RDS >> Mysql

Node.js returnerer resultat fra MySQL-forespørgsel

Du skal kun udføre behandlingen af ​​resultaterne fra db-forespørgslen ved et tilbagekald. Ligesom.

function getColour(username, roomCount, callback) { connection.query('SELECT hexcode FROM colours WHERE precedence = ?', [roomCount], function(err, result) { if (err) callback(err,null); else callback(null,result[0].hexcode); }); } //call Fn for db query with callback getColour("yourname",4, function(err,data){ if (err) { // error handling code goes here console.log("ERROR : ",err); } else { // code to execute on data retrieval console.log("result from db is : ",data); } });

  1. Kan ikke oprette forbindelse til Postgres DB på grund af godkendelsestype 10 understøttes ikke

  2. Sådan returneres Unix-tidsstemplet i SQL Server (T-SQL)

  3. Opret et SQL Server Agent Job ved hjælp af T-SQL

  4. Slå en advarsel fra i sqlalchemy