2010年11月29日 星期一

Python 2.7 Connect MySQL

依序下載程式安裝
1. Python 2.7
2. SetupTools 2.7
3. MySQL-python 1.2.3 for windows and python 2.7

測試 Connect MySQL 是否可運作
1. 開啟 Python 2.7 IDLE
2. 編輯測試程式
>>> import MySQLdb
>>> db = MySQLdb.connect(host="localhost", user="xxxx", passwd="xxxx", db="xxxx")
>>> cursor = db.cursor()
>>> cursor.execute("select * from system_user")
2L
>>> result = cursor.fetchall()
>>> for record in result :
        print record[0]


USERE00000000000000000001
USERE00000000000000000002
>>>