Get the App
SLTechnology News&Howtos  ›  Database  › 

Use python to operate mysql database (which is implemented through classes to facilitate the addition of functions)

Shulou Source: shulou.com Published: 2022-06-01 17:32:12 10月01日 Update

#-*-coding: utf-8-* "Created on Sun Nov 27 18:57:44 2016@author: toby"import MySQLdb'test_db'class MysqlHelper (object): def _ _ init__ (self,hosts,users,password,dbname): self.conn = MySQLdb.connect (host=hosts,user=users,passwd=password)" Db=dbname) self.cur = self.conn.cursor (MySQLdb.cursors.DictCursor) # get all the data in the database def Get_all_data (self): sql = "select * from user" self.cur.execute (sql) data = self.cur.fetchall () self.cur.close () self.conn.close () return data a = MysqlHelper ('127.0.0.1) '1qazure EDC print a.Get_all_data ()

Tags: Data database utf-8 function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Huawei Docker Linux