Answer the question
In order to leave comments, you need to log in
Why doesn't INSERT INTO work with pymysql?
It is not possible to execute a simple SQL command using the pymysql module, but for example, SELECT works.
Here is the main script:
from connect import get_connection
import pymysql
connection = get_connection()
c = connection.cursor()
sql = "INSERT INTO test (id, name) VALUES (10, 'test')"
c.execute(sql)
connection.close()
import pymysql.cursors
# Подключиться к базе данных.
def get_connection():
connection=pymysql.connect(host='localhost',
user='root',
password='',
db='test',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
print ("Успешное подключение к базе данных!\n\n\n")
connection.commit()
return connection
Answer the question
In order to leave comments, you need to log in
I don't know what it is PyMySQL
, but the network gives advice :
connection = get_connection()
c = connection.cursor()
sql = "INSERT INTO test (id, name) VALUES (10, 'test')"
c.execute(sql)
connection.commit()
connection.close()
Perhaps there already is a record with id=10
Doesn't give any errors?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question