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