连接数据库 输入值 存入数据库 关闭
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' and 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()