午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

python使用pymysql模塊操作MySQL

瀏覽:19日期:2022-06-16 15:58:52
目錄實(shí)例一:插入數(shù)據(jù)實(shí)例二:獲取某個(gè)表全部數(shù)據(jù)實(shí)例三:根據(jù)cName模糊搜索實(shí)例四:修改數(shù)據(jù)實(shí)例五:刪除數(shù)據(jù)實(shí)例一:插入數(shù)據(jù)

python使用pymysql模塊操作MySQL

import pymysqlimport tkinter as tkconn = pymysql.connect(host=’localhost’, user=’root’, passwd=’root’, db=’okzl’, charset=’utf8’)master = tk.Tk()master.title('插入供應(yīng)商信息')master.geometry(’350x300’)tk.Label(master, text=’cName’).place(x=30,y=10)tk.Label(master, text=’address’).place(x=30,y=40)tk.Label(master, text=’linkman’).place(x=30,y=70)tk.Label(master, text=’linkPhone’).place(x=30,y=100)tk.Label(master, text=’credit’).place(x=30,y=130)tk.Label(master, text=’remark’).place(x=30,y=160)in1=tk.Entry(master, width=30).place(x=100,y=10)in2=tk.Entry(master, width=30).place(x=100,y=40)in3=tk.Entry(master, width=30).place(x=100,y=70)in3=tk.Entry(master, width=30).place(x=100,y=100)in3=tk.Entry(master, width=30).place(x=100,y=130)in3=tk.Entry(master, width=30).place(x=100,y=160)def insert(): cur = conn.cursor() # 伸出手 sql1 = 'insert into pro(cName,address,linkman,linkPhone,credit,remark) values(%s,%s,%s,%s,%s,%s)' temp2 = ( ) cur.execute(sql1, temp2) conn.commit() cur.close()tk.Button(master,text=’插入’,width=8,command=insert).place(x=140,y=220)master.mainloop()conn.close()

python使用pymysql模塊操作MySQL

成功插入數(shù)據(jù)

實(shí)例二:獲取某個(gè)表全部數(shù)據(jù)

import pymysqlconn = pymysql.connect(host=’localhost’, user=’root’, passwd=’root’, db=’okzl’, charset=’utf8’)cur = conn.cursor()cur.execute(’select * from pro’)data = cur.fetchall()cur.close()print(data)conn.close()

python使用pymysql模塊操作MySQL

實(shí)例三:根據(jù)cName模糊搜索

import pymysqlimport tkinter as tkconn = pymysql.connect(host=’localhost’, user=’root’, passwd=’root’, db=’okzl’, charset=’utf8’) # 連接數(shù)據(jù)庫master = tk.Tk()master.title('搜索某客戶信息')master.geometry(’350x300’)e = tk.Entry(master)e.pack(padx=20, pady=20)def tosearch(): cur = conn.cursor() temp2 = (e.get(), '%' + e.get() + '%') cur.execute('select * from pro where cName like %s or cName like %s ', temp2) data = cur.fetchall() cur.close() print(data)tk.Button(master, text=’搜索’, width=8, command=tosearch).pack(padx=20, pady=50)master.mainloop()conn.close()

python使用pymysql模塊操作MySQL

實(shí)例四:修改數(shù)據(jù)

根據(jù)數(shù)據(jù)庫自動給數(shù)據(jù)生成的id來確認(rèn)目標(biāo)和修改數(shù)據(jù)

python使用pymysql模塊操作MySQL

import pymysqlimport tkinter as tkconn = pymysql.connect(host=’localhost’, user=’root’, passwd=’root’, db=’okzl’, charset=’utf8’)master = tk.Tk()master.title('修改供應(yīng)商信息')master.geometry(’350x300’)tk.Label(master, text=’cName’).place(x=30,y=10)tk.Label(master, text=’address’).place(x=30,y=40)tk.Label(master, text=’linkman’).place(x=30,y=70)tk.Label(master, text=’linkPhone’).place(x=30,y=100)tk.Label(master, text=’credit’).place(x=30,y=130)tk.Label(master, text=’remark’).place(x=30,y=160)tk.Label(master, text=’目標(biāo)id’).place(x=30,y=190)in1=tk.Entry(master, width=30)in1.place(x=100,y=10)in2=tk.Entry(master, width=30)in2.place(x=100,y=40)in3=tk.Entry(master, width=30)in3.place(x=100,y=70)in4=tk.Entry(master, width=30)in4.place(x=100,y=100)in5=tk.Entry(master, width=30)in5.place(x=100,y=130)in6=tk.Entry(master, width=30)in6.place(x=100,y=160)in7=tk.Entry(master, width=30)in7.place(x=100,y=190)def update(): cur = conn.cursor() # 伸出手 sql1 = 'update pro set cName=%s, address=%s,linkman=%s,linkPhone=%s,credit=%s,remark=%s where id=%s' temp2 = (in1.get(),in2.get(),in3.get(),in4.get(),in5.get(),in6.get(),in7.get()) cur.execute(sql1, temp2) conn.commit() cur.close()tk.Button(master,text=’確認(rèn)修改’,width=8,command=update).place(x=140,y=220)master.mainloop()conn.close()

python使用pymysql模塊操作MySQL

實(shí)例五:刪除數(shù)據(jù)

這里是根據(jù)id刪除

sql1 = 'delete from pro where id=%s'temp1 = str(n)cur.execute(sql1, temp1)conn.commit()cur.close()

上述實(shí)例均為基礎(chǔ)實(shí)現(xiàn)操作舉例,實(shí)際操作中可根據(jù)需求更改程序和sql語句實(shí)現(xiàn)目標(biāo)效果

以上就是python使用pymysql模塊操作MySQL的詳細(xì)內(nèi)容,更多關(guān)于python 用pymysql操作MySQL的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 男女国产视频 | 日韩av网页 | 国产人成在线 | 成人看片网 | 日韩精品国产一区 | 五月婷婷激情综合 | 欧美va在线观看 | 日韩在线视频免费观看 | 黄色av资源 | 国产精品久久久久久久天堂第1集 | 日韩网站在线播放 | 欧美脚交视频 | 女人日批视频 | 自拍偷拍另类 | 国产免费看黄 | 欧美在线一二三 | 欧美在线视频免费 | 国产高清一区 | 综合中文字幕 | 蜜桃传媒一区二区 | 国产性猛交╳xxx乱大交 | 亚洲成人激情在线 | www久久久久久 | 日日摸日日干 | 五月婷婷丁香网 | 1024国产精品 | 操一操| 山东少妇露脸刺激对白在线 | 精品久久久久久久久久久久 | 欧美高清不卡 | 一级成人黄色片 | av在线播放一区 | 九九一级片 | 亚洲一级黄色录像 | 欧美一区二区三区在线视频 | 亚洲视频91 | 中国一级片在线观看 | 九九在线 | 50一60岁老妇女毛片 | 欧美色图另类图片 | 69中文字幕 |