Switching Databases
Carsten Haese
carsten.haese at gmail.com
Mon Nov 23 09:17:44 EST 2009
Victor Subervi wrote:
> 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.
Do not paraphrase error messages. Copy and paste the actual error
message and traceback.
> But I thought
> I'd closed the first one!
You thought you did, but did you? The code snippet above doesn't show
any code that closes a database connection.
> So, I replaced the last 3 lines with this:
>
> cursor.execute('use %s;' % db)
>
> but it didn't like that, either.
Do not paraphrase error messages. Copy and paste the actual error
message and traceback.
--
Carsten Haese
http://informixdb.sourceforge.net
More information about the Python-list
mailing list