June 2000
Intermediate to advanced
556 pages
8h 45m
English
We use the following simple MySQL program to prove that the Python MySQL interface is up and running.
CD-ROM reference=15003.txt
C>type testmysql.py
"""
Program to test Python interface to MySQL
"""
import MySQL
# Connect to MySQL.
db=MySQL.connect('','')
# Select the mysql database. This database is
# always available in a MySQL system.
db.selectdb("mysql")
# Retrieve a list of tables in that database.
query = db.query("show tables")
# Retrieve the rows that make up the query result.
rows=query.fetchrows()
# Print them out.
print rows
The result of executing the program is shown below.
CD-ROM reference=15004.txt
C>python testmysql.py
[['db'], ['host'], ['user']]
Read now
Unlock full access