Nodejs using Express to operate MySQL additions and deletions

Source: Internet
Author: User

If you do not know how to connect to the database, see http://www.cnblogs.com/complete94/p/6714757.html

I think when everyone knows how to connect to the database, then

Here we go

var express = require ("Express");

var mysql = require ("MySQL");

var basedate = require ("./mysql"); Information for database connections

var $sql = mysql.createconnection (Basedate.mysql);

$sql. connect ();

Inquire

var select = "Select * from Mono"//Suppose our data table is called Mono * representative query all content select query

$sql. Query (Select,function (err,res) {//err) error message res is the query to the content is all inside

if (err) {

Console.log ("error", err)///We print out, error message

}else {

Console.log (RES)//print out the contents of our Enquiry

}

})

Increase

var insert = "INSERT into mono (id,name,age) value (3," China ", 5000)"; We added a piece of data to the data sheet mono; id=3;name= China; age=5000 This is a new piece of data.

$sql. Query (Insert,function (err,res) {

if (err) {

Console.log ("error", err)

}else{

Console.log ("Add Success", res)//We print out the information to add success

}

})

Modify

var updata = "Updata mono set name= ' China ' shere name= ' Beijing '"; We have the name data in the Mono table equal to China, and instead Beijing

$sql. Query (Updata,function (err,res) {

if (err) {

Console.log ("error", err)

}else{

Console.log ("Modified successfully", RES)

}

})

Delete

var del = "Delete from mono id=3"//We delete the id=3 data in the Mono table Delete Delete

$sql. Query (Del,function (err.res) {

if (err) {
Console.log (ERR)
}else{
Console.log ("Successful Delete", res)
}

})

Nodejs using Express to operate MySQL additions and deletions

Related Article

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.