I cannot save the information to the Database (PYTHON MYSQL)

Asked

Viewed 98 times

0

I am trying to insert this query, but it n registers in the Mysql table, however I realize that it is accessing right, because it always uses a position of 'Cod' which is primaryKey

*when using the database SQL string it normally inserts

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()

1 answer

2


Missed the bd.commit(). Basically, the data does not enter the database at the time you execute the query. It is necessary to commit to perform the actual 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()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.