problem description
node accepts the request to query the database with a value and returns an error write after end
related codes
// console.log(startTime,id,endTime)
var express = require("express");
var app = express();
var mysql = require("mysql");
var connection = mysql.createConnection({
host: "127.0.0.1", //
user: "root", //
port : "3306",
password: "", //
database: "lbst" //
});
connection.connect();
if(startTime != null) {
// var sql="select from lb_admin_addon where starTime= "+startTime+" and id="+ id +" and endTime="+endTime;
// select * from market_orders where createdate>="2010-03-01 00:00:00" and createdate<"2016-03-02 00:00:00"
//
var sql = `
SELECT * FROM lb_addmin_taglist WHERE timestamp>="${startTime}" AND timestamp<"${endTime}"
`
} else {
var sql = "select * from lb_admin_msg";
}
var sqlarr = [];
connection.query(sql, function selectCB(err, results, fields) {
if(err) {
throw err;
}
if(results) {
for(var a = 0; a < results.length; aPP) {
sqlarr.push(results[a])
}
}
connection.end();
})
function ztstInterval() {
clearInterval(searchArr)
}
var num = 0;
var searchArr = setInterval(function() {
numPP;
console.log(sqlarr.length)
if(sqlarr.length != 0) {
ztstInterval();
sqlarr = JSON.stringify(sqlarr)
// response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
var msg = {
"": 200,
data: sqlarr
}
response.write(1);
response.end(msg);
}
}, 1000)