天天看點

pydobc連接配接sql server資料庫

self.my = pyodbc.connect("DRIVER={SQL Server};SERVER=127.0.0.1;\
DATABASE=MY;UID=python;PWD=python")
        self.cursor = self.my.cursor()
        self.cursor.execute("select sno, passwd from s where sno = '{0}'".format(user))
        get = self.cursor.fetchall()
           

對于fetchall()如果沒有查到,傳回[ ],而不是None。

繼續閱讀