#coding: Utf-8 ' Created on October 25, 2017 @author:li.liu ' import pymysqldb=pymysql.connect (' localhost ', ' root ', ' root ' , ' Test ', charset= ' UTF8 ') m=db.cursor () "Try: #a =raw_input (' Please enter SQL statement ' + ' \ n ') 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\t '% (d,c), print ' \ R ' Except:print ' SQL statement error, check ' Finally:db.close () ' While True:try:s=raw_input (' Please enter SQL statement ' + ' \ n ') 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 (' UT F-8 ') print '%s:%s\t '% (d,c), print ' \ r ' print ' \ R ' except:print ' SQL statement error, please check '
Implementing MySQL Query db instance with Python