# -*- coding: utf-8 -*- import pymssql # Create your views here. # 数据库服务器信息 server = "localhost" user = "sa" password = "hzp" database = "test1" charset = 'utf-8' class Data: def getdata(sql, ele1='', ele2=''): # get connection conn = pymssql.connect(server, user, password, database, charset) # var cursor cur = conn.cursor() # get data cur.execute(sql, ele1) rows = cur.fetchall() cur.close() conn.close() return rows sql = u'select top 1 description from fruit where description is not null ' data = Data.getdata(sql) data2 = data[0][0] print(data2) # print(data[0][0].encode('utf-8')) # # string.strip() :trim the ' ' in strings # print(data[0][1].strip())
python 查询数据库,后中文乱码
最新推荐文章于 2024-09-10 17:56:10 发布