MySQL Forums
Forum List  »  Connector/Python

Re: Reg: Configurng MySQL in Python
Posted by: Lalit Shakya
Date: January 16, 2011 10:29PM

install MySQLdb module on your m/c Ist





import MySQLdb
db= MySQLdb.connect(host="localhost", user="username", passwd="password",db="databasename")
try:
name1 = raw_input("Please enter a name: ")
if name1 == "" :
exit
address1 = raw_input("Please enter the address: ")
city1 = raw_input("Enter the city: ")
except:
print 'Invalid value'
exit
print "name: [" + name1 + "]"
print "address: ["+ address1 + "]"
print "city: ["+ city1 + "]"
cursor = db.cursor()
stmt = "INSERT INTO admin(name, address, city) VALUES ('"
stmt = stmt + name1
stmt = stmt + "', '"
stmt = stmt + address1
stmt = stmt + "', '"
stmt = stmt + city1
stmt = stmt + "')"
cursor.execute(stmt)
print "Record added!"
cursor.close ()
db.commit ()

Options: ReplyQuote


Subject
Written By
Posted
January 13, 2011 07:23AM
Re: Reg: Configurng MySQL in Python
January 16, 2011 10:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.