#-*- coding: UTF-8 -*-
import MySQLdb
try:
connection = MySQLdb.connect(user="root",passwd="root",host="localhost",db="test",charset="utf8")
except:
print "could not connect to mysql server."
exit(0)
try:
cursor = connection.cursor()
#cursor.execute( " select * from news where id = 1 " )
count = cursor.execute("select * from jtg_test " )
#统计记录
print '总共有%s条记录',count
print " row secect:", cursor.rowcount
for row in cursor.fetchall():
print "note : ",row[0],row[1]
cursor.close()
except:
print "fetch error"
exit(0)
try:
connection.select_db('analyse_event')
cur=connection.cursor()
value=['bb','ccc']
cur.execute('insert into jtg_test(name,password)values(%s,%s)',value)
# connection.commit()
values = []
for i in range(20):
values.append(('ss'+str(i),'helo'+str(i)))
cur.executemany('insert into jtg_test(name,password)values(%s,%s)',values)
connection.commit()
cur.close()
connection.close()
except:
print "failor"
exit(0)