FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-100-day/day-080/insert_data.py at master · kuncstat/python-100-day · GitHub
kuncstat
/
python-100-day
Public
forked from
JustDoPython/python-100-day
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-100-day
/
day-080
/
insert_data.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (24 loc) · 585 Bytes
Breadcrumbs
python-100-day
/
day-080
/
insert_data.py
Copy path
File metadata and controls
29 lines (24 loc) · 585 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
pymysql
# 打开数据库连接
conn
=
pymysql
.
connect
(
host
=
"127.0.0.1"
,
user
=
"root"
,
password
=
"123456"
,
database
=
"test_db"
,
charset
=
"utf8"
)
# 获取连接下的游标
cursor_test
=
conn
.
cursor
()
# 使用预处理语句创建表
sql
=
"""INSERT INTO user1(FIRST_NAME,
LAST_NAME, AGE, SEX, INCOME)
VALUES ('Fei', 'Fei', 20, 'M', 1000)"""
try
:
# 执行sql语句
cursor_test
.
execute
(
sql
)
# 提交到数据库执行
conn
.
commit
()
except
:
# 如果发生错误则回滚
conn
.
rollback
()
# 关闭数据库连接
conn
.
close
()
Back
|
FazBrowse Home
|
New Git URL