zurückgibt Wert Ich mag ein Datum aus einer MySQL-Datenbank erhalten und ich verwende Node.js mit SQL für sie, das ist mein Server-Code:Node.js - SQL-Funktion nicht
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '127.0.0.1',
user : 'root',
password : '',
database : 'temp'
});
function getData(res){
var tempVal = 1377;
connection.connect();
connection.query('SELECT * FROM tempvalues ORDER BY datetime DESC LIMIT 1', function(err, rows){
console.log(rows);
tempVal = rows;
});
connection.end();
return tempVal;
}
app.get('/', function(req, res){
res.sendfile('index.html');
});
io.on('connection', function(socket){
socket.on('clientSent', function(data){
if(data == "GET")
socket.emit("serverSent", getData());
})
})
http.listen(3000, function(){
console.log('listening on *:3000');
});
Wenn i Gehe zu localhost:3000
Ich bekomme nur 1377
als Wert, aber nicht den tatsächlichen Wert aus der Datenbank, obwohl die Konsole die richtigen Werte druckt. Warum das?
Dank! Das funktioniert :) – binaryBigInt