# -*- coding: utf-8 -*- """ Created on Sun Nov 27 18:57:44
# -*- 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)
#获取数据库所有数据
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()
--结束END--
本文标题: 用python操作mysql数据库(之通过类实现,方便添加功能)
本文链接: https://www.lsjlt.com/news/36586.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-28
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0