zoukankan      html  css  js  c++  java
  • nodejs链接mysql数据库,执行简单的增删改查操作

    var mysql = require('mysql');
    var conn = mysql.createConnection({
        host: 'localhost',
        user: 'root',
        password: '',
        database:'nodejs',
        port: 3306
    });
    conn.connect();
    
    //查询
    // conn.query('SELECT * from user where name="wangzhiwei"', function(err, result) {
    //     if (err) throw err;
    //     console.log(result);
    // })
    
    //新增
    // conn.query('insert into user (username,password) values("huxiaona","123456")', function(err, result) {
    //     if (err) throw err;
    //     console.log(result);
    // })
    
    //删除
    // conn.query('delete from user where username="wupeigui"', function(err, result) {
    //     if (err) throw err;
    //     console.log(result);
    // })
    
    conn.query('update user set id="1" where username="huxiaona"',function(err,result){
        if (err) {throw err};
        console.log("修改数据成功");
    })
    
    conn.end();

    有一点要指出的是,npm install mysql 的时候,要在程序里面,就算你把mysql加载到nodejs的node_modules文件夹里面也不顶事,可能是我操作不对吧,有知道的说下啊,谢谢,前端有了数据后感觉立马吊吊的,一会就建一个网站管理系统玩去,简单明了,不过nodejs要怎么才能用session,我百度了一下都说是用cookie来替换,这样不太好吧

  • 相关阅读:
    B 基因改造
    A 密码锁
    Leetcode(884)-索引处的解码字符串
    Leetcode(885)- 救生艇
    Leetcode(23)-合并K个排序链表
    关于优先队列的总结II
    重载运算符问题
    Leetcode(22)-括号生成
    Leetcode(102)-二叉树的层次遍历
    Leetcode(82)-删除排序链表中的重复元素 II
  • 原文地址:https://www.cnblogs.com/busicu/p/4261497.html
Copyright © 2011-2022 走看看