Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

#-*-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 ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report