Switching Databases

Victor Subervi victorsubervi at gmail.com
Mon Nov 23 05:47:20 EST 2009


Hi;
I have the following code:

import MySQLdb
...
user, passwd, db, host = login()
db = MySQLdb.connect(host, user, passwd, 'cart')
cursor= db.cursor()
...
cursor.close()
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?
TIA,
Victor
-------------- 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