const express = require('express') const mysql = require('mysql2')
const app = express()
app.get('/',async (req , res)=>{ const config = getConfig()
const promisePool = mysql.createPool(config).promise() var students = await promisePool.query(` insert into student(name,score,gender,class_id) values (?,?,?,?) `,['坤坤',60,0,2]) res.send({ ok:1, data: students[0] }) })
app.listen(3000,()=>{ console.log('服务器已启动,3000端口号正在监听...'); })
function getConfig(){ return { host:'127.0.0.1', port: 3306, user: 'root', password: 'Zpl13189417387', database:'test1', connectionLimit:1 } }
|