# -*- 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) #獲取數(shù)據(jù)庫所有數(shù)據(jù) 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','root','1qaz#EDC','test_db') print a.Get_all_data()
網(wǎng)站標題:用python操作mysql數(shù)據(jù)庫(之通過類實現(xiàn),方便添加功能)
轉載源于:http://jinyejixie.com/article44/pshsee.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、營銷型網(wǎng)站建設、定制網(wǎng)站、標簽優(yōu)化、網(wǎng)站策劃、網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)