Skip to content

Instantly share code, notes, and snippets.

@heylastway
Created October 31, 2019 16:41
Show Gist options
  • Save heylastway/e242e18cae772bcb1ec98caf99ed835d to your computer and use it in GitHub Desktop.
Save heylastway/e242e18cae772bcb1ec98caf99ed835d to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import MySQLdb
# Connect
db = MySQLdb.connect(host="localhost",
user="appuser",
passwd="",
db="onco")
cursor = db.cursor()
# Execute SQL select statement
cursor.execute("SELECT * FROM location")
# Commit your changes if writing
# In this case, we are only reading data
# db.commit()
# Get the number of rows in the resultset
numrows = cursor.rowcount
# Get and display one row at a time
for x in range(0, numrows):
row = cursor.fetchone()
print row[0], "-->", row[1]
# Close the connection
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment