RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
用python操作mysql数据库(之“更新”操作)
#!/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()

网站标题:用python操作mysql数据库(之“更新”操作)
链接地址:http://sczitong.cn/article/pddsch.html