我刚刚开始接触 Node.js.我来自 PHP 背景,所以我相当习惯使用 MySQL 来满足我所有的数据库需求.
I've just started getting into Node.js. I come from a PHP background, so I'm fairly used to using MySQL for all my database needs.
如何将 MySQL 与 Node.js 结合使用?
How can I use MySQL with Node.js?
查看 node.js 模块列表
node-mysql 看起来很简单:
node-mysql looks simple enough:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'example.org',
user : 'bob',
password : 'secret',
});
connection.connect(function(err) {
// connected! (unless `err` is set)
});
查询:
var post = {id: 1, title: 'Hello MySQL'};
var query = connection.query('INSERT INTO posts SET ?', post, function(err, result) {
// Neat!
});
console.log(query.sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQL'
这篇关于带有 Node.js 的 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!