国产成人AV无码一二三区,少女1到100集,国产精品久久久久精品综合紧,巜公妇之诱感肉欲HD在线播放

文章 > MySQL > mysql??槿绾问褂?/a>

mysql??槿绾问褂?/p>

mysql模块

头像

小妮浅浅

2021-08-28 09:32:474854浏览 · 0收藏 · 0评论

1、在使用之前,创建一个名为demo的数据库,同时定义一个名为demo_tabel的表操作log。

C:\Users\James>mysql -u root -p
Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.16 MySQL Community Server - GPL
 
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> create database demo;
Query OK, 1 row affected (0.12 sec)
 
mysql> create table demo_tabel
    -> (
    -> id int(11),
    -> name varchar(30),
    -> sex varchar(4)
    -> );
Query OK, 0 rows affected (0.49 sec)
mysql> show tables;
+----------------+
| Tables_in_demo |
+----------------+
| demo_table     |
+----------------+
1 row in set (0.02 sec)
 
mysql>

2、在开始访问前,编写一个简单的server.js代码,返回表中的数据。

http://localhost:3000/query/

// server.js
const Koa = require('koa');
const app = new Koa();
const mysql = require('mysql')
const Router = require('koa-router')
 
/*
 一般情况下操作数据库是很复杂的读写过程,不只是一个会话,
 如果直接用会话操作,就需要每次会话都要配置连接参数。
 因此需要连接池管理会话。
*/
const pool = mysql.createPool({
  host: 'localhost',          // 数据库地址
  user: 'root',               // 登录数据的用户名
  password: 'helloworld',     // 密码
  database: 'demo'            // 所用的数据库
})
 
const port = 3000
const hostName = '127.0.0.1'
 
const router = new Router();
 
const query = (sql, values) => {
  return new Promise((resolve, reject) => {
    pool.getConnection((error, connection) => {
      connection.query(sql,values, (error, results) => {
        if(error) throw error
        connection.release()
        resolve(results)
      })
    })
  })
}
 
router.get('/', async (ctx, next) => {
  ctx.res.type = 'application/json'
  ctx.body = await query('select * from demo_table')
});
 
app
  .use(router.routes())
  .use(router.allowedMethods());
app.listen(port, hostName);
console.log(`http://${hostName}:${port}`)

以上就是mysql模块的使用,希望对大家有所帮助。更多mysql学习指路:MySQL

推荐操作系统:windows7系统、mysql5.8、DELL G3电脑

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

《别告诉我丈夫》电影| 我的老师中韩双字ID| 苏苏的骚浪短笔趣阁小说| 吃春晚药后妈妈疯了怎么对付| 五十款夜间禁用APP粉色视频| 蜜糖直播| 《再来一次好吗》动浸| 老婆同意了别人轮流联系我| 器材室轮-J-(4)对着镜子| 倒插莲花男女之间的寓意| 挺进朋友人妻张婉莹身体| 《訾花交换做爰》| 免费观看已满十八岁电视剧高清版| 麻花MV在线看免费观看电视剧| 情满四合院| 老公把闺蜜干的嗷嗷叫| 兄弟换麦子4国语中字| 樱花视频在线观看免费高清电视剧| 土豆网下载| 天使之城电影| 老头天天吃我奶躁我的动图Q| D124| 伦理《少妇的滋味》完整版| 公厕被偷窃视频大全| 美女比基尼游泳跳舞视频| 4399在线观看免费高清电视剧 | 疯狂二人房间荷尔蒙爆发原声| 乱浮生(高干)BY行魅小说免费..| 妈妈的闺蜜韩剧结局原声在线观看..| 妈妈装睡配合孩子阴阳调和| 《请好好疼爱里面》免费观看| 农村真实亲子乱子伦| 成品动漫网站入口网页版怎样| 《不戴套瑜伽教练3》| 茄子视频| B大与小哪个好| 品色TANG| 《黏糊糊的你》免费观看| 《请好好疼爱里面》免费观看| (NP、高H、纯肉、真空)| 朝铜光