Created
August 17, 2012 05:28
-
-
Save utsavsabharwal/3376193 to your computer and use it in GitHub Desktop.
MySQL Python API Example
This file contains hidden or 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
| from datetime import datetime | |
| import hashlib | |
| import MySQLdb | |
| conn = MySQLdb.connect (host = "localhost", user = "root", db = "spider") | |
| cursor = conn.cursor () | |
| #INSERTION/UPDATE Statements | |
| sql="insert ignore into url_queue select * from something" | |
| cursor.execute(sql) | |
| conn.commit() | |
| #SELECTION Statements | |
| sql="select * from url_queue LIMIT 10" | |
| cursor.execute(sql) | |
| rows = cursor.fetchall() #each row is a tuple while each coloumn of that row is also a tuple ((a,b,c), (d,e,f)) | |
| for row in rows: | |
| print list(row) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment