1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import pymssql #数据库连接信息 conn = pymssql.connect(host = "192.168.175.161" ,database = "Test" ,user = "sa" ,password = "!QAZ2wsx" ) #定义游标 cur = conn.cursor() #执行SQL cur.execute( "SELECT id, name FROM userid" ) #返回结果所有行 cur.fetchall() #返回结果读取下一行 cur.fetchone() #在结果中读取指定数目的行 cur.fetchmany(size = None ) #关闭数据库连接 conn.close() |