|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
MySQLdb
#建立连接
conn
=
MySQLdb.connect(host
=
'127.0.0.1'
,user
=
'root'
,passwd
=
'1qaz#EDC'
,db
=
'test_db'
)
cur
=
conn.cursor()
#对数据进行操作
sql
=
"update user set name=%s where id=7"
#定义sql语句,用于修改ID为7的name字段
params
=
(
"zhongjw"
,)
#修改为"zhongjw"
cur.execute(sql,params)
conn.commit()
#提交请求
#关闭数据库连接
cur.close()
conn.close()
|
本文转自 TtrToby 51CTO博客,原文链接:http://blog.51cto.com/freshair/1876237