A
A
Artyom2018-04-12 16:07:19
MySQL
Artyom, 2018-04-12 16:07:19

Python + MySql: Why is no data being added to the table?

Following code

import MySQLdb
n = 401
conn = MySQLdb.connect(user='root', host='localhost', db='main_database')
cursor = conn.cursor()
for i in range(1, n):
    cursor.execute(f'INSERT INTO lessons (id, title, text1, image1, text2, image2) VALUES ({i}, "", "", "", "", "");')
conn.close()
logically should enter 400 records into the database.
After I launch
import MySQLdb
conn = MySQLdb.connect(user='root', host='localhost', db='main_database')
cursor = conn.cursor()
cursor.execute("SELECT * FROM lessons")
row = cursor.fetchone()
print(row)
conn.close()

This code should display these 400 entries, but for some reason it displays "None".
Where am I wrong? Are the records entered incorrectly or am I reading them incorrectly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2018-04-13
@TheProgrammer256

cursor.execute("INSERT INTO employees (first_name) VALUES (%s)", ('Jane'))
conn.commit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question