标签:style blog http color os 数据
连接数据库 输入值 存入数据库 关闭
import string import mysql.connector conn=mysql.connector.connect(user=‘root‘,password=‘test‘,database=‘dalian‘,use_unicode=True) cursor=conn.cursor() a=raw_input(‘enter an id: ‘) b=raw_input(‘enter a name: ‘) while(a!=‘quit‘ or b!=‘quit‘): print a print b cursor.execute(‘insert into hi(id,name) values(%s,%s)‘,[a,b]) cursor.rowcount conn.commit() cursor.execute(‘select * from hi‘) values=cursor.fetchall() print values a=raw_input(‘enter an id: ‘) b=raw_input(‘enter a name: ‘) else: print ‘done‘ cursor.close() conn.close()
python操作mysql数据库,布布扣,bubuko.com
标签:style blog http color os 数据
原文地址:http://www.cnblogs.com/SouthRain/p/3851722.html