January 2019
Beginner
318 pages
8h 23m
English
Now, we are going to create a table and we will insert some data into it. For that, create a create_insert_data.py script and write the following content in it:
import MySQLdb as mdbcon_obj = mdb.connect('localhost', 'test_user', 'test123', 'test')with con_obj: cur_obj = con_obj.cursor() cur_obj.execute("DROP TABLE IF EXISTS books") cur_obj.execute("CREATE TABLE books(Id INT PRIMARY KEY AUTO_INCREMENT, Name VARCHAR(100))") cur_obj.execute("INSERT INTO books(Name) VALUES('Harry Potter')") cur_obj.execute("INSERT INTO books(Name) VALUES('Lord of the rings')") cur_obj.execute("INSERT INTO books(Name) VALUES('Murder on the Orient Express')") cur_obj.execute("INSERT INTO books(Name) VALUES('The adventures of ...Read now
Unlock full access