本文介紹了帶有 Node.js 的 MySQL的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我剛剛開始接觸 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 — 一個實現 MySQL 協議的 node.js 模塊
- node-mysql2 — 另一個純 JS 異步驅動程序.流水線,準備好的語句.
- node-mysql-libmysqlclient — 基于 libmysqlclient 的 MySQL 異步綁定
- node-mysql — A node.js module implementing the MySQL protocol
- node-mysql2 — Yet another pure JS async driver. Pipelining, prepared statements.
- node-mysql-libmysqlclient — MySQL asynchronous bindings based on libmysqlclient
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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!