连接到数据库时查询似乎无法正常工作,并且json字符串似乎为空,我收到以下错误 {“代码”:“ PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR”,“致命”:false} < / p>
const express = require('express');
const cors = require('cors');
const mysql = require('mysql');
const app = express();
const selectAllClients = "SELECT * from clients";
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'dashboard',
multipleStatements: true
});
console.log(connection);
app.use(cors());
app.get('/clients', (req, res) =>{
connection.query(selectAllClients, (err, results) => {
if(err){
return res.send(err);
}
else
{
return res.json({
data: results
})
}
});
});
app.listen(4000, () => {
console.log('Server listening on port 4000')
});