Node connects to MySQL and makes additional deletions and checks

Source: Internet
Author: User

Npm:

The full name of NPM is the node Package Manager, which resembles Ruby's Gem,python pypl, setuptools,php pear, which is the packet manager in Nodejs. The Nodejs itself provides the basic modules. However, the development of practical applications on these basic modules requires more work. There are already nearly thousands of nodejs libraries or frameworks on NPM that can help nodejs developers with more complex applications in every way.

Install NPM (under Unix):

Installing node modules with NPM

such as MySQL:

NPM install MySQL

Connect MySQL database with node, and add and revise, directly paste code.

var mysql = require (' mysql '); var conn = Mysql.createconnection ({host: ' localhost ', User: ' Root ', password: ' Root ', database: ' Nodedb ', port:8889}); Conn.connect (); Console.log ("Connect Mysql Success"); var selectsql = ' SELECT * fro M USERTB '; var insertsql = ' INSERT INTO USERTB values ("Conan"), ("fens.me") '; var deletesql = ' Delete from T_user '; var update SQL = ' Update t_user set name= ' Conan Update ' where name= ' Conan ';//selectconn.query (Selectsql, function (err, rows) {if    (err) Console.log (err); Console.log ("Select ==>");    for (var i in rows) {Console.log (rows[i]);  }});////insert//Conn.query (Insertsql, function (ERR1, res1) {//if (ERR1) Console.log (ERR1);//Console.log ("Insert Return ==> ");//Console.log (RES1);//});////delete//Conn.query (Deletesql, function (ERR2, res2) {//if (err 2) Console.log (ERR2);//Console.log ("DELETE Return ==>");//Console.log (RES2);/});////update//Conn.query (U Pdatesql, function (ERR3, RES3) {// if (ERR3) Console.log (ERR3);//Console.log ("UPDATE Return ==>");//Console.log (RES3);/}); Conn.end (); 

Node connects to MySQL and makes additional deletions and checks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.