这是请求的方法
app.get('/api/:id', function (req, res) {
connection.connect();
connection.query('SELECT * from testmodel_url WhERE id='+req.params.id, function(err, rows, fields) {
if (err) throw err;
let obj={
'status':200,
'message':'success',
'data':rows
}
res.json(obj)
});
connection.end();
});
使用postman第一次请求可以获得正确的结果
再次请求就会报错
events.js:182
throw er; // Unhandled 'error' event
^
Error: Cannot enqueue Handshake after invoking quit.
at Protocol._validateEnqueue (C:\bin\pro\express\node_modules\_mysql@2.15.0@
mysql\lib\protocol\Protocol.js:204:16)
at Protocol._enqueue (C:\bin\pro\express\node_modules\_mysql@2.15.0@mysql\li
b\protocol\Protocol.js:139:13)
at Protocol.handshake (C:\bin\pro\express\node_modules\_mysql@2.15.0@mysql\l
ib\protocol\Protocol.js:52:23)
at Connection.connect (C:\bin\pro\express\node_modules\_mysql@2.15.0@mysql\l
ib\Connection.js:130:18)
at C:\bin\pro\express\index.js:29:16
at Layer.handle [as handle_request] (C:\bin\pro\express\node_modules\_expres
s@4.16.3@express\lib\router\layer.js:95:5)
at next (C:\bin\pro\express\node_modules\_express@4.16.3@express\lib\router\
route.js:137:13)
at Route.dispatch (C:\bin\pro\express\node_modules\_express@4.16.3@express\l
ib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\bin\pro\express\node_modules\_expres
s@4.16.3@express\lib\router\layer.js:95:5)
at C:\bin\pro\express\node_modules\_express@4.16.3@express\lib\router\index.
js:281:22
繁星点点滴滴
相关分类