-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.js
35 lines (29 loc) · 1.02 KB
/
mysql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var mysql=require('mysql')
var connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'123456',
database:'test',
port:3305
})
connection.connect();
var sql='SELECT * FROM websites';
connection.query(sql,function(error,result){
if (error) return error;
console.log('--------------------------SELECT----------------------------');
console.log('The solution is: ', result);
})
var addSql = 'INSERT INTO websites(Id,name,url,alexa,country) VALUES(0,?,?,?,?)';
var addSqlParams = ['菜鸟工具', 'https://c.runoob.com','23453', 'CN'];
//增
connection.query(addSql,addSqlParams,function (err, result) {
if(err){
console.log('[INSERT ERROR] - ',err.message);
return;
}
console.log('--------------------------INSERT----------------------------');
//console.log('INSERT ID:',result.insertId);
console.log('INSERT ID:',result);
console.log('-----------------------------------------------------------------\n\n');
});
connection.end();