Skip to content

Instantly share code, notes, and snippets.

@davepape
Created April 2, 2014 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepape/9937742 to your computer and use it in GitHub Desktop.
Save davepape/9937742 to your computer and use it in GitHub Desktop.
# Script to insert a new city into the example 'world' database
import MySQLdb
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world')
cur = db.cursor()
print "enter new city's name:"
name = raw_input()
print "enter new city's country code:"
code = raw_input()
print "enter new city's population:"
population = raw_input()
# Note: this uses a parameterized query in order to make sure the data is safe
query = "insert into City (Name, CountryCode, Population) values (%s,%s,%s)"
cur.execute(query, (name,code,population))
cur.close()
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment