我曾多次尝试用stackoverflow中的其他问题来解决我的问题,但都没有成功。我现在正在学习python。在
我知道如何用PHP来做,但我需要用python来做。在
我有一个表dentistas
,有4列id、web、email、telefono。在
我从另一个文件导入一个包含web url的列表。在
我想在web列中插入这些weburl。在
我现在使用的代码不会在终端中显示错误,但不会向表中插入任何内容:
# coding=utf-8
import MySQLdb
from parser import lista
bd = MySQLdb.connect('localhost', 'testuser', 'test123', 'leads') # Connecting to the database
cursor = bd.cursor() # Creating the cursor
for x in lista:
cursor.execute("INSERT INTO dentistas(web) VALUES(%s)", (x,))
您忘记了
commit()
并保存当前数据库状态。在尝试在循环之后使用
bd.commit()
。在相关问题 更多 >
编程相关推荐