JavaScript操作MYSQL数据库

Node.js操作数据库:


var mysql  = require('mysql');

var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : '',
    port: '3306',
    database: 'test'
});

connection.connect();

var  sql = 'SELECT * FROM user';
//查
connection.query(sql,function (err, result) {
    if(err){
        console.log('[SELECT ERROR] - ',err.message);
        return;
    }

    console.log('--------------------------SELECT----------------------------');
    console.log(result);
    console.log('------------------------------------------------------------\n\n');
});

connection.end();

转载于:https://www.cnblogs.com/nizuohao/p/10893630.html

你可能感兴趣的:(JavaScript操作MYSQL数据库)