交互式爱情
以下是一种方法,使用MySQLdb,它只支持Python 2:#!/usr/bin/pythonimport MySQLdb# Connectdb = MySQLdb.connect(host="localhost",
user="appuser",
passwd="",
db="onco")cursor = db.cursor()# Execute SQL select statementcursor.execute
("SELECT * FROM location")# Commit your changes if writing# In this case, we are only reading data# db.commit()
# Get the number of rows in the resultsetnumrows = cursor.rowcount# Get and display one row at a
timefor x in range(0, numrows):
row = cursor.fetchone()
print row[0], "-->", row[1]# Close the connectiondb.close()参考文献