J
J
JackShcherbakov2018-11-10 21:22:36
MySQL
JackShcherbakov, 2018-11-10 21:22:36

How to commit SQL queries in Python DB-API?

Hello!
Downloaded and installed the MySQL-connector/Python driver from Oracle. MySQL installed.
I am doing the following procedure:

import mysql.connector
dbconfig = {
  'host' : '127.0.0.1',
  'user' : 'root',
  'password' : 'PaSsWoRd1234',
  'database' : 'database1234'}
conn = mysql.connector.connect(**dbconfig)
_SQL = """INSERT INTO some_table VALUES(NULL, 50)"""
cursor=conn.cursor()
cursor.execute(_SQL)
#Пытаюсь закомитить запрос
cursor.commit()
#ОШИБКА! У cursor нету атрибута commit()

What am I doing wrong?
Thanks in advance to everyone who helps!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-11-10
@JackShcherbakov

The connection is responsible for committing transactions, not the cursor
conn.commit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question