hurriedly% 2011-04-28 12:05 采纳率: 100%
浏览 46
已采纳

带有 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条回答 默认 最新

  • 7*4 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 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)