MySQL Forums
Forum List  »  Connector/Python

Re: Dissecting a query using Python
Posted by: Jonathan Stephens
Date: April 29, 2005 08:45PM

This works for me:

import MySQLdb
db = MySQLdb.connect(host="localhost", user="jon", passwd="jonpass", db="mdbd")

cursor = db.cursor()
date = "1980-06-15"
query = "SELECT firstname, lastname, dob FROM members WHERE dob < %s LIMIT 10"
cursor.execute(query, (date,))

while 1: # next three lines indented
row = cursor.fetchone()
if row is None: break
print "NAME: %s %s; DOB: %s" % (row[0], row[1], row[2])

cursor.close()

If you're not using MySQLdb (and it doesn't look like you are), you should check it out: see http://sourceforge.net/projects/mysql-python

Jon Stephens
MySQL Documentation Team @ Oracle

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote


Subject
Written By
Posted
Re: Dissecting a query using Python
April 29, 2005 08:45PM


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.