Sun Jul 22, 2012 4:14 pm
http://packages.python.org/oursql/
$ pip install oursql
import oursql
## connect to database on local machine
conn = oursql.connect(host='localhost', user='root', passwd='root', db='codemiles')
## get the cursor object, by the specifying the cursor class to be used,
## if left blank defaults will be used
mycurs = conn.cursor(oursql.DictCursor)
## run query
mycurs.execute("SELECT * FROM User")
## fetching the data( rows)
while (1):
myrow = mycurs.fetchone()
## row empty marks end of resultset
if row == None:
break
## Print Data
print "%s" % (myrow['FirstName'])
print "%s" % (myrow['LastName'])
curs.execute("SELECT * FROM Department WHERE NumOfSudents>= ? ",(300)
## fetching results
while (1):
row = curs.fetchone()
## row empty marks end of resultset
if row == None:
break
## Print Data
print "%s" % (row['Department_Name'])
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.