铁路校友-我拆过的坑cycx

主页:www.j6f.cn知识星球,快手号、抖音号、视频号、微信公众号、百家号、个人博客网站,同名。

关闭 Node.js 与 MySQL 数据库连接

  15:44 更新

要正常关闭数据库连接,请在connection对象上调用end()方法。


end()方法确保在数据库连接关闭之前始终执行所有剩余的查询。


 

connection.end(function(err) {  if (err) {    return console.log('error:' + err.message);
  }  console.log('Close the database connection.');
});SQL

 

要立即强制连接,可以使用destroy()方法。 destroy()方法保证不会再为连接触发回调或事件。


connection.destroy();Js

请注意,destroy()方法不会像end()方法那样采取任何回调参数。


Powered By Z-BlogPHP 1.7.3

Copyright Your WebSite.Some Rights Reserved.