// 云函数入口文件
const cloud = require(‘wx-server-sdk’)
const mysql=require(‘mysql2/promise’)
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
const connection=await mysql.createConnection({
host:‘mysql57.rdsmj85epr606zi.rds.bj.baidubce.com’,
user:‘sam’,
database:‘samMYSQL’,
password:‘xxxxxxxx’,
})
const [rows, fields] = await connection.execute(‘SELECT version();’)
return rows
}
错误如下:
WAService.js:1 Uncaught (in promise) Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 8a0ca2a7-f0f0-11e9-af3a-525400192d0e, cloud function service error code -504002, error message Cannot read property ‘execute’ of undefined; at cloud.callFunction api;
at new u (WAService.js:1)
at d (WAService.js:1)
at f (WAService.js:1)
at Function.success (WAService.js:1)
at WAService.js:1
at C (WAService.js:1)
at i.<anonymous> (WAService.js:1)
at i.emit (WAService.js:1)
at Rs (WAService.js:1)
at WAService.js:1