sqlserver数据库python简单查询操作,注意一定要地址填对。
代码如下:
import pymssql
class Demo(object):
def __init__(self):
self.host = '10.194.XX.X'
self.user = 'sa'
self.passwd = '0000XXXX'
self.port = 40000
def diao(self,sql):
self.db_connect = pymssql.connect(server=self.host, user=self.user, password=self.passwd,database='cfss_rpt_db', port=self.port)
self.cursor = self.db_connect.cursor()
self.cursor.execute(sql)
sql_values = self.cursor.fetchall()
return sql_values
if __name__ == '__main__':
sql = 'select tote_id from tote_rpt_title where ts=0x0000000000002A7A'
cursor = Demo().diao(sql)
print(cursor)