六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 30|回复: 0

python操作mysql

[复制链接]

升级  62%

120

主题

120

主题

120

主题

举人

Rank: 3Rank: 3

积分
386
 楼主| 发表于 2013-1-15 02:45:50 | 显示全部楼层 |阅读模式
#-*- encoding: gb2312 -*-import os, sys, stringimport MySQLdbtry:        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] 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表