I can not write information to the database (PYTHON \ MYSQL)

0

I am trying to insert this query, but it does not register in the MySql table, but I realize that it is accessing right, because it always uses a position of the 'cod' that is primaryKey

* When I use the string in the SQL database it inserts normally

bd = MySQLdb.connect(host="localhost", user="root", passwd="", db="medicbd") cursor = bd.cursor() cursor.execute("INSERT INTO 'paciente' ('nome', 'nascimento', 'telefone', 'celular','cpf','estado','cidade') VALUES('ghfhgf','04-06-1997','359920556','0569875468','021465821','mg','kj')") cursor.close() bd.close()

    
asked by anonymous 27.05.2018 / 21:54

1 answer

1

The bd.commit() was missing. Basically, the data does not go into the database at the time you run the query. You need to commit to actually do the actions.

bd = MySQLdb.connect(host="localhost", user="root", passwd="", db="medicbd")
cursor = bd.cursor()
cursor.execute("INSERT INTO 'paciente' ('nome', 'nascimento', 'telefone', 'celular','cpf','estado','cidade') VALUES('ghfhgf','04-06-1997','359920556','0569875468','021465821','mg','kj')")
bd.commit()
cursor.close()
bd.close()
    
27.05.2018 / 21:56