亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

文檔上傳分享

老師,你的案例文檔能不能上傳分享下

正在回答

1 回答

#mysqlhelper.py另存即可

import?pymysql

class?dbhelper():
????def?__init__(self,host,port,user,passwd,db,charset="utf8"):
????????self.host=host
????????self.port=port
????????self.user=user
????????self.passwd=passwd
????????self.db=db
????????self.charset=charset
????#創建一個鏈接
????def?connection(self):
????????#創建連接
????????self.conn=pymysql.connect(host=self.host,port=self.port,
????????user=self.user,passwd=self.passwd,
????????db=self.db,charset=self.charset)
????????#創建游標
????????self.cur=self.conn.cursor()
????#關閉鏈接
????def?closeconnection(self):
????????self.cur.close()
????????self.conn.close()
????#查詢一條語句
????def?getonedata(self,sql):
????????try:
????????????self.connection()
????????????self.cur.execute(sql)
????????????result=self.cur.fetchone()
????????????self.closeconnection()
????????except?Exception:
????????????print(Exception)
????????return?result
????#添加/修改/刪除
????def?executedata(self,sql):
????????try:
????????????self.connection()
????????????self.cur.execute(sql)
????????????self.conn.commit()
????????????self.closeconnection()
????????except?Exception:
????????????print(Exception)
????#批量插入
????def?executemanydata(self,sql,vals):
????????try:
????????????self.connection()
????????????self.cur.executemany(sql,vals)
????????????self.conn.commit()
????????????self.closeconnection()
????????except?Exception:
????????????print(Exception)


1 回復 有任何疑惑可以回復我~
#1

慕慕8209279

為何我寫的這句def__int__(self,host,port,user,passwd,charset="utf8"):是報錯的
2021-07-04 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Python辦公自動化
  • 參與學習       49732    人
  • 解答問題       163    個

以實際工作場景出發,利用python高效快捷覆蓋全方位辦公自動化內容。

進入課程

文檔上傳分享

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號