小程序里knex操作腾讯云的云数据库MySQL,总是出错,求解

如下,我自己单独尝试连接mysql和腾讯暴露的接口连接都不行,求大神帮忙指导下。
另外,我将后端代码上传到腾讯云上面了,如何查看后端代码console.log的打印数据?

module.exports = async (ctx, next) => {

  if (ctx.state.$wxInfo.loginState === 1) {
  
    /*const { mysql: config } = require('../config');
    var knex = require('knex')({
      client: 'mysql',
      connection: {
        host: config.host,
        port: config.port,
        user: config.user,
        password: config.pass,
        database: config.db,
        charset: config.char,
        multipleStatements: true
      }
    });
    knex('question_sort').select('id').then(res => {
       console.log(res)
      ctx.state.data = res;
    })*/
    
    const { mysql } = require('../qcloud')
    mysql('question_sort').select('id').then(res => {
      ctx.state.data = res;
    })
    
  } else {
    ctx.state.code = -1
  }
}
阅读 6.4k
2 个回答

mysql查询也是异步,前面加await就好了

新手上路,请多包涵

楼主,你的问题解决了吗?能交流一下你最后是怎么做的吗?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题