const http = require("http");
const mysql = require("mysql");
const server = http.createServer((req,res)=>{
const connection = mysql.createConnection({
host:"localhost",
port:3306,
user:'root',
password:'root',
database:'web37'
})
let sql = "select * from user";
connection.query(sql,(error,results)=>{
if(error){
throw error
}
console.log(results);
results = JSON.stringify(results)
res.setHeader('Content-Type','text/plain;charset=utf-8')
res.end(results)
})
})
server.listen(3001,()=>console.log("服务启动"))
node.js原生链接数据库查询数据
最新推荐文章于 2022-11-28 17:31:32 发布