// 云函数入口文件
|
|
const cloud = require('wx-server-sdk')
|
|
//引入mysql操作模块
|
|
const mysql = require('mysql2/promise')
|
|
cloud.init()
|
|
|
|
// 云函数入口函数
|
|
exports.main = async (event, context) => {
|
|
const wxContext = cloud.getWXContext()
|
|
try {
|
|
const connection = await mysql.createConnection({
|
|
host: "sh-cynosdbmysql-grp-102eitfe.sql.tencentcdb.com",
|
|
port:23345,
|
|
database: "yicanyishi",
|
|
user: "Test",
|
|
password: "1Canyishi"
|
|
})
|
|
const [rows, fields] = await connection.execute('SELECT version();')
|
|
connection.end()
|
|
return rows;
|
|
|
|
} catch (err) {
|
|
console.log("链接错误", err)
|
|
return err
|
|
}
|
|
|
|
}
|