nodejs对开源数据库mysql、firebird的支持

本文介绍了如何使用Node.js通过npm安装并连接到MySQL和Firebird两种开源数据库。针对MySQL,我们安装了'mysql'库并展示了基本用法;对于Firebird,我们安装了'node-firebird'库,提供了示例代码来说明其连接和操作数据库的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装 Npm install mysql

Mysql示例:

var mysql = require('mysql');
var conn = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '123456',
database:'lobtao',
port: 3306
});
conn.connect();
conn.query('select username,email from tbl_user limit 5', function(err, rows, fields) {
if (err) throw err;

console.log('The solution is: ', rows[0].solution);

console.log(rows);
});
conn.end();

安装 Npm install node-firebird

Firebird示例:

var Firebird = require('node-firebird');
var options = {};

options.host = '127.0.0.1';
options.port = 3050;
//options.database = 'D:/delphi/firebird/Firebird-2.1.5.18497-0_Win32/examples/empbuild/EMPLOYEE.FDB';//绝对路径
options.database = 'EMPLOYEE';//别名
options.user = 'SYSDBA';
options.password = 'masterkey';

Firebird.attach(options, function(err, db) {
if (err) throw err;
// db = DATABASE
db.query('select * from country', function(err, result) {
res.end( JSON.stringify(result) );
// IMPORTANT: close the connection
db.detach();
});
});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值