How To Insert Data Into MySQL Database Table Using Python
import mysql.connector
connection = mysql.connector.connect(
host='localhost',
user='root', password='',
port='3306',
database='test_py'
)
c = connection.cursor()
def insertData():
insert_query = "INSERT INTO `users_2`
"`firstname`, `lastname`, `email`, `age`)
"VALUES (%s,%s,%s,%s)"
vals = ("TheFirstName","TheLastName","TheEmail@gmail.com",42)
c.execute(insert_query,vals)
connection.commit()
print(c.lastrowid)
insertData()
OUTPUT: