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

安装 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();
});
});


你可能感兴趣的:(nodejs)