Created
April 19, 2022 20:37
-
-
Save Derrick-Sherrill/9454e54b850c28f631b7f6e7b6e0a3d6 to your computer and use it in GitHub Desktop.
For SQL online video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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