相关疑难解决方法(0)

如何在python中使用单个MySQL查询更新多行?

#!/usr/bin/python

# -*- coding: utf-8 -*-
import MySQLdb as mdb

con = mdb.connect('localhost', 'root', 'root', 'kuis')

with con:

    cur = con.cursor()
    cur.execute("UPDATE Writers SET Name = %s WHERE Id = %s ",
        ("new_value" , "3"))
    print "Number of rows updated:",  cur.rowcount
Run Code Online (Sandbox Code Playgroud)


使用上面的代码,数据库kuis中表Writer的第三行值用new_value更新,输出将是Number od行更新:1
我应该如何同时更新多行?

python mysql mysql-python

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

mysql ×1

mysql-python ×1

python ×1