最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I query MySQL with node.js? - Stack Overflow

programmeradmin2浏览0评论

I am going to make a client-server application using Node.js, and I want to use a MySQL database for storing some of the data. I need to know how to query a database with server-side JavaScript.

I am going to make a client-server application using Node.js, and I want to use a MySQL database for storing some of the data. I need to know how to query a database with server-side JavaScript.

Share Improve this question edited Mar 30, 2012 at 8:08 Thein Hla Maw 6831 gold badge9 silver badges28 bronze badges asked Mar 29, 2012 at 12:27 WingbladeWingblade 10.1k10 gold badges36 silver badges52 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Search the module library for mysql and you will get many modules that will let you do that including mysql, db-mysql, and easy-mysql.

npm install node-mysql

var mysql = require('mysql'),
    client = mysql.createClient({
        user: 'root',
        password: 'root',
    });

mysql.query('SELECT * FROM my_table', function(err, results, fields) {
    //have fun         
    client.end();
});

There are other libraries as well that all have slightly different APIs.

发布评论

评论列表(0)

  1. 暂无评论