Switching Databases

Victor Subervi victorsubervi at gmail.com
Mon Nov 23 11:47:20 CET 2009

I have the following code:

import MySQLdb
user, passwd, db, host = login()
db = MySQLdb.connect(host, user, passwd, 'cart')
cursor= db.cursor()
db = MySQLdb.connect(host, user, passwd, db)
cursor= db.cursor()

Now, python complains about me opening a new connection. But I thought I'd
closed the first one! So, I replaced the last 3 lines with this:

cursor.execute('use %s;' % db)

but it didn't like that, either. Any way to switch databases?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091123/781e1f20/attachment.html>

More information about the Python-list mailing list