#coding:utf-8 ''' Created on 2017年10月25日 @author: li.liu ''' import pymysql db=pymysql.connect('localhost','root','root','test',charset='utf8') m=db.cursor() ''' try: #a=raw_input('请输入sql语句'+' ') m.execute('select * from student') a=m.fetchall() b=m.description print b print a for i in range(len(a)): n='' for j in range(len(b)): c=str(a[i][j]) d=b[j][0].encode('utf-8') print '%s: %s '%(d,c), print ' ' except: print 'SQL语句错误,请检查' finally: db.close() ''' while True: try: s=raw_input('请输入sql语句'+' ') if s=='exit':break m.execute(s) a=m.fetchall() b=m.description for i in range(len(a)): n='' for j in range(len(b)): c=str(a[i][j]) d=b[j][0].encode('utf-8') print '%s: %s '%(d,c), print ' ' print ' ' except: print 'SQL语句错误,请检查'