Python下MySQL for Win32

使用例子:

import MySQLdb
try:
    conn = MySQLdb.connect(host='localhost',user='root',passwd='1',db='test_python')
except Exception,e:
    print e
    sys.exit()
cursor = conn.cursor()
sql = "create table if not exists test1(name varchar(128) primary key, age int(4))"
cursor.execute(sql)
sql = "insert into test1(name, age) values (%s, %s)"
val = (("abc", 24), ("cde", 25), ("fgh", 26))
try:
    cursor.executemany(sql, val)
except Exception, e:
    print e
conn.commit()

下载地址:MySQL-python-1.2.3.win32-py2.6

分享到:更多 ()

抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址