nodejs能获取mysql的表名吗

2025-01-19 06:59:38
推荐回答(2个)
回答1:

可以
其实实现方式还是用sql语句查到表明,在传给js

回答2:

,nodejs获取具体某张数据表信息,具体内容如下

var mysql = require('mysql');
var conn = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '123456',
database:'mysql',
port: 3306
});
var tempArr = new Array();
conn.connect();
conn.query("show tables",function(err,results)
{
if(err)
{
throw err;
}

if(results)
{
for(var i = 0; i < results.length; i++)
{
tempArr[i] = results[i];
var a = tempArr[i];
console.log(typeof(results[i]));
console.log(a);
var temp = "";
temp+=a.Tables_in_mysql;
console.log("temp"+i+" "+temp);
conn.query("select * from"+ " "+ temp,function selectCb(err,result,fields){
if(err)
{
throw err;
}
console.log("数据表:" + results[i]);
console.log(fields);
});
}
}
})