Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
InterfaceAutoTest
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TestAuto
InterfaceAutoTest
Commits
15f953e5
Commit
15f953e5
authored
Apr 30, 2021
by
taoke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加musql操作类
parent
c711f152
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
2 deletions
+60
-2
common/db.py
+59
-1
service/login.py
+1
-1
No files found.
common/db.py
View file @
15f953e5
import
redis
import
redis
,
pymysql
# redis类
class
RedisBase
:
...
...
@@ -17,6 +17,64 @@ class RedisString(RedisBase):
return
result
# mysql类
class
MYSQL
:
"""
对pymysql的简单封装
"""
def
__init__
(
self
,
host
,
port
,
user
,
pwd
,
db
):
self
.
host
=
host
self
.
port
=
port
self
.
user
=
user
self
.
pwd
=
pwd
self
.
db
=
db
def
__GetConnect
(
self
):
"""
得到连接信息
返回: conn.cursor()
"""
self
.
conn
=
pymysql
.
connect
(
host
=
self
.
host
,
port
=
self
.
port
,
user
=
self
.
user
,
password
=
self
.
pwd
,
database
=
self
.
db
,
charset
=
"utf8"
)
cur
=
self
.
conn
.
cursor
()
return
cur
def
ExecuQuery
(
self
,
sql
):
"""
执行查询语句
返回的是一个包含tuple的list,list的元素是记录行,tuple的元素是每行记录的字段
调用示例:
ms = MYSQL(host="localhost",user="sa",pwd="123456",db="PythonWeiboStatistics")
resList = ms.ExecQuery("SELECT id,NickName FROM WeiBoUser")
for (id,NickName) in resList:
print str(id),NickName
"""
cur
=
self
.
__GetConnect
()
cur
.
execute
(
sql
)
resList
=
cur
.
fetchall
()
#查询所有,得到列表 [(1,2,3),(1,2,3),(1,2,3)]
# resList = cur.fetchone() # 查询一个,得到1个(不用这个)
#查询完毕后必须关闭连接
self
.
conn
.
close
()
return
resList
def
ExecuNonQuery
(
self
,
sql
):
"""
执行非查询语句
调用示例:
cur = self.__GetConnect()
cur.execute(sql)
self.conn.commit()
self.conn.close()
"""
cur
=
self
.
__GetConnect
()
cur
.
execute
(
sql
)
self
.
conn
.
commit
()
self
.
conn
.
close
()
if
__name__
==
'__main__'
:
...
...
service/login.py
View file @
15f953e5
...
...
@@ -7,7 +7,7 @@ def sso_login():
def
bmy_login
():
"""企业云登录"""
"""
开发1112221
"""
""""""
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment