1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import pymysql db = pymysql.connect("localhost","testuser","test123","TESTDB" ) cursor = db.cursor()
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, LAST_NAME, AGE, SEX, INCOME) VALUES (%s, %s, %s, %s, %s )" % ('Mac', 'Mohan', 20, 'M', 2000) try: cursor.execute(sql) print(cursor.lastrowid) print(db.insert_id()) db.commit() except: db.rollback() db.close()
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, LAST_NAME, AGE, SEX, INCOME) VALUES (%s, %s, %s, %s, %s )" cursor.execute(sql, ('Mac', 'Mohan', 20, 'M', 2000))
|