JS读取mysql数据,易懂

代码:

 1 var mysql  = require(‘mysql‘);
 2 var connection = mysql.createConnection({
 3     host     : ‘localhost‘,
 4     user     : ‘root‘,
 5     password : ‘password‘,
 6     port: ‘3306‘,
 7     database: ‘nufix‘
 8 });
 9 connection.connect();
10 
11 var  sql = ‘select * from dependency_info‘;
12 connection.query(sql,function (err, results) {
13     if(err){
14         console.log(‘[SELECT ERROR] - ‘,err.message);
15         return;
16     }
17 
18     if(results)
19     {
20         for(var i = 0; i < results.length; i++)
21         {
22             console.log("%d\t%s\t%s", i, results[i].project_name, results[i].dependency);
23             break;
24         }
25     }
26 });
27 connection.end();

 

JS读取mysql数据,易懂

上一篇:MySQL——创建表格时的提醒


下一篇:Python的print用法