[Tutor] Python + MySQL , my first simple program does not gives results
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Jan 19 19:50:14 CET 2006
On Thu, 19 Jan 2006, John Joseph wrote:
> Hi
> I tried out my first Pyhton program with MySQL
> I was trying to get the some result , eg
> describe table, select * from table
Hi John,
Unlike Java, Python doesn't force you to put everything in a class. You
can try the simpler:
######
import MySQLdb
db = MySQLdb.connect(host="localhost",user =
"john",password = "asdlkj", db = learnpython)
cursor = db.cursor()
cursor.execute(" describe contact" )
cursor.execute(" SELECT * from contact" )
######
from toplevel.
> but my program does not give the expected results ,
What do you expect to see, and from where?
A call to cursor.execute() sets the cursor up so that subsequent calls to
cursor.fetchone() will give us result rows. See:
http://www.amk.ca/python/writing/DB-API.html
You need to add some code to print out the result set. The link above is
a tutorial to the database interface that should help you get started.
Good luck!
More information about the Tutor
mailing list