ITeye博客

python操作mysql

lampeter123 · 2009-12-10 16:30 · Python · 编程语言 · OS · SQL · MySQL · Python · Markdown

#-*- encoding: gb2312 -*-

import os, sys, string
import MySQLdb

try:
        conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='zftest')
except Exception, e:
        print e
        sys.exit()
cursor = conn.cursor()

sql = "INSERT INTO album (artist,title,created,updated) VALUES ('77','mytest','hongfu demo','2007-07-09')";
sql = "update album set title = '9999999999' where id = 44"
#sql = 'delete from album where id = 41'
#print sql 
cursor.execute(sql)
conn.commit()
sql = "select * from album"
cursor.execute(sql)
datas = cursor.fetchone()
#datas = cursor.fetchall()
print datas
#for s in datas:
#        print s[1] + '++++++' + s[2] + '+++++++' + s[3]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。