如何在node.js中使用两个数据库连接? (mysql) [英] How can I use two database connections in node.js? (mysql)

查看:614
本文介绍了如何在node.js中使用两个数据库连接? (mysql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用express和mysql模块对两个数据库进行请求,并侦听端口8000。

I want to make requests for two databases using express and mysql modules and listen on port 8000.

推荐答案

您可以创建使用mysql节点程序包的多个数据库连接,例如:

You could create multiple db connections using mysql node package like:

var mysql      = require('mysql');

var connection = mysql.createConnection({...});
var otherConnection = mysql.createConnection({...});

请参见node-mysql 文档

See node-mysql documentation

createConnection在每次调用时创建一个新的单独的数据库连接对象。

createConnection creates a new, separate database connection object on each call.

这篇关于如何在node.js中使用两个数据库连接? (mysql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆