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条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错