Using list_dbs() and list_tables function of MySQLDB with python

sonu u2_sonu at yahoo.co.in
Wed Jan 15 13:22:21 CET 2003


dear friends,

i m using list_dbs() and list_tables() function in my application but
finding a problem in running this code successfully.

The code i m using is:
# !/usr/bin/Python
import MySQLdb
hostname = "192.168.0.11"	
username = "root"
password = ""
database = "test"
conn = MySQLdb.connect (hostname, username, password, database)
for db in conn.list_dbs():
    for tbl in conn.list_tables(db[0]):
        cursor = conn.cursor();
        cursor.execute("SELECT * FROM " + tbl[0]);
        print cursor.fetchone();
        cursor.close();

conn.close();  

i m getting the error:
Traceback (most recent call last):
  File "E:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\My Documents\myscript.py", line 8, in ?
    for db in conn.list_dbs():
AttributeError: Connection instance has no attribute 'list_dbs'

Please help me in solving the problem.
i will be really thankful to you
sonu




More information about the Python-list mailing list