Created
April 2, 2014 15:30
-
-
Save davepape/9936463 to your computer and use it in GitHub Desktop.
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
# Query the example "world" database using MySQLdb | |
import MySQLdb | |
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world') | |
cur = db.cursor() | |
cur.execute("SELECT ID, Name, Population from City order by Name limit 3") | |
for row in cur.fetchall(): | |
print "ID:",row[0], "Name:", row[1], "Pop:", row[2] | |
cur.close() | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment