nodejs mysql

Wizardlsw發表於2015-04-04

https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/ A very good article

 

http://blog.csdn.net/zxsrendong/article/details/17006185

var mysql = require('mysql';

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

connection.connect(function(err){
    if(err) console.log('err');
    else{
// connection.query('select * from suers where sex=:sex', {sex:1}, ... connection.query(
'select * from users where sex=?', [1], function(err2, rows){ if(err2) console.log('query error'); else {
console.log(rows);
connection.end();
        } }); } });

 

相關文章