From c4662990305287bba8bb1496af4ec7cc553209d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E4=BA=91?= <3329280162@qq.com> Date: Sat, 25 Feb 2023 02:46:37 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9D=8E=E5=AD=90=E4=BA=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李子云 <3329280162@qq.com> --- .../zy.js" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "\346\235\216\345\255\220\344\272\221/2-22\345\242\236\345\210\240\346\224\271\346\237\245/zy.js" diff --git "a/\346\235\216\345\255\220\344\272\221/2-22\345\242\236\345\210\240\346\224\271\346\237\245/zy.js" "b/\346\235\216\345\255\220\344\272\221/2-22\345\242\236\345\210\240\346\224\271\346\237\245/zy.js" new file mode 100644 index 0000000..bfc5892 --- /dev/null +++ "b/\346\235\216\345\255\220\344\272\221/2-22\345\242\236\345\210\240\346\224\271\346\237\245/zy.js" @@ -0,0 +1,42 @@ +// 作业:建一个用户表(有姓名,年龄,性别,创建时间,修改时间),使用模块加mysql模块,实现对数据的增删改查 +// ### 修改时记得,把修改时间改成修改时的时间,能实现分页(选做) +let mysql =require("mysql"); +let con=mysql.createConnection({host:"127.0.0.1",user:"root",password:"root",port:"3306",database:"users"}); +con.connect(); + +//创建时间戳 +let time=new Date() +let times=time.getFullYear()+"/"+time.getMonth()+"/"+time.getDate()+"/"+time.getHours()+"/"+time.getMinutes()+"/"+time.getSeconds() + + +//增加 +let insertsql="INSERT into user(`name`,`age`,`sex`,`create`,`update`)value('何建恒','18','女','"+times+"','"+times+"'),('成毅','23','男','"+times+"','"+times+"'),('李宏毅','23','男','"+times+"','"+times+"'),('赵丽颖','23','女','"+times+"','"+times+"')" + +con.query(insertsql,(err,data)=>{ + console.log(err) + console.log(data) +}) + +//删除 +let deletesql="delete from user where id=3" +con.query(deletesql,(err,data)=>{ + console.log(err) + console.log(data) +}) + +//修改 +let updatesql="update user set name='美少女战士',update='"+time+"' where id=2" +con.query(updatesql,(err,data)=>{ + console.log(err) + console.log(data) +}) +//查询 +let sel=function(page){ + let selectsql="select * from user limit "+(6*page-6)+","+(6); + con.query(selectsql,(err,data)=>{ + console.log(err) + console.log(data) + }) +} +sel(1) +con.end(); \ No newline at end of file -- Gitee