MySQL Connectivity with Python

Great article over at DevShed on connecting to a MySQL database using the Python language. Folks familiar with ADO or with SQL Pass-through and the VFP way of manipulating cursors will be comfortable with code like this:

#!/usr/bin/python
# import MySQL module
import MySQLdb
# connect
db = MySQLdb.connect(host="localhost", 
user="joe", passwd="secret",db="db56a")
# create a cursor
cursor = db.cursor()
# execute SQL statement
cursor.execute("SELECT * FROM animals")
# get the resultset as a tuple
result = cursor.fetchall()
# iterate through resultset
for record in result:
        print record[0] , "-->", record[1]

Powered by WordPress. Designed by Woo Themes

This work by Ted Roche is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States.