Skip to content

Instantly share code, notes, and snippets.

@Derrick-Sherrill
Created April 19, 2022 20:37
Show Gist options
  • Save Derrick-Sherrill/9454e54b850c28f631b7f6e7b6e0a3d6 to your computer and use it in GitHub Desktop.
Save Derrick-Sherrill/9454e54b850c28f631b7f6e7b6e0a3d6 to your computer and use it in GitHub Desktop.
For SQL online video
import os
import mysql.connector
mydb = mysql.connector.connect(
host='',
user='',
password='',
port=3306,
database=''
)
sql = "SELECT * FROM customers;"
mycursor = mydb.cursor()
mycursor.execute(sql)
if 'INSERT' in sql:
mydb.commit() # required to make table changes
print("Last inserted ID:", mycursor.lastrowid)
if 'SELECT' in sql:
myresult = mycursor.fetchall()
for x in myresult:
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment