要先安一个包才能使用QtSql通过新立得安装 import PyQt5.QtSql as sql db=sql.QSqlDatabase.addDatabase(‘QMYSQL‘) db.setDatabaseName(‘test1‘) db.setUserName(‘root‘) db.setPassword(‘123‘) db.open() query=sql.QSqlQuery(‘select * from a1‘) query.first() for i in range(query.size()): print(query.value(0),query.value(1)) query.next() db.close()
时间: 2024-10-12 11:31:49