Created
April 2, 2014 15:34
-
-
Save davepape/9936522 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
# Perform an 'update' query on the sample database, with data input by the user | |
import MySQLdb | |
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world') | |
cur = db.cursor() | |
print 'enter new name for City 1:' | |
newname = raw_input() | |
# Include the data in the query; *NOTE* that this does not do any safety checks / escaping of the data - it's an easy target for an SQL injection attack | |
query = "update City set Name='" + newname + "' where id=1" | |
print query | |
cur.execute(query) | |
cur.close() | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment