1

I tried many times to solve my problem with other questions in stackoverflow with no success. I'm learning python right now.

I know how to do it in PHP but I need to do it in python.

I have a table dentistas with 4 columns id, web, email, telefono.

And I import from another file with a list containing web urls.

I want to insert those websurls in the web column.

The code that im using right now doesn't shows me an error in the terminal, but doesn't insert anything to the table:

# 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,))

1 Answer 1

2

You forgot to commit() and save your current database state.

Try using bd.commit() after the loop.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, was the commit() ;)
forgot the previous answer.... have you comitted after making the changes in your database?
100% turnaround haha but you are right! See this stackoverflow.com/questions/2847999/… question why you have to commit cursor executions that change your database.
Yes, was the commit()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.