7*4 2011-04-28 12:05 采纳率: 50%
浏览 334
已采纳

带有 Node.js 的 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.

How can I use MySQL with Node.js?

转载于:https://stackoverflow.com/questions/5818312/mysql-with-node-js

  • 写回答

8条回答 默认 最新

  • local-host 2011-04-28 12:51
    关注

    Check out the node.js module list

    • 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 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)
    });
    

    Queries:

    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'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?