-1
所有行我要删除表中符合特定值的所有行(userId
)的Python MySQLdb的删除符合条件
我一直在看这篇文章(Python MySQLdb iterate through table)设法得到它的工作如何我想要它。
我有一个users
表和images
表。
images
:
在我的Python脚本,我只在用户名拉。因此,首先
我需要使用传入的
userName
获得用户的userId
。 (我有以下SELECT
声明,但不知道如何将结果分配给一个变量)import MySQLdb dbb = MySQLdb.connect(host="ipaddress", user="root", passwd="myPassword", db="myDatabase") user_name = "user" cursor = dbb.cursor() cursor.execute("""SELECT userId FROM users WHERE userName ='%s'""" (user_name)) var users_id = 0 // need to assign users_id to the selected userId from above code
然后
我需要通过
images
表遍历和删除与相应的userId
cursor2 = dbb.cursor() cursor2.execute("""SELECT FROM images WHERE userId='%s'""" (users_id)) for cursor2: //don't think this is right... //DELETE all rows with matching users_id
什么python脚本?你还没有发布任何代码。 –
@ScottHunter新增了我能做的 – velkoon