forked from Echoyy9/Personnel-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_test.py
34 lines (32 loc) · 866 Bytes
/
db_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pymysql
'''
#连接数据库
con = pymysql.connect(host='localhost',
user='user',
password='123456',
db='personnel_man',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with con.cursor() as cursor:
#读取单条记录
sql = "select 'd_no','d_name','s_no' from 'department' "
cursor.execute(sql)
result = cursor.fetchone()
print(result)
finally:
con.close()
'''
db = pymysql.connect("localhost","user","123456","personnel_man")
cursor = db.cursor()
try:
cursor.execute("select * from department")
results=cursor.fetchall()
for row in results:
dno = row[0]
dname = row[1]
sno = row[2]
print(dname)
except:
print("error")
db.close()