bzyx / 5 lat, 10 miesięcy temu | Download | Plaintext | Odpowiedz |

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# this little monkey has to be here
app = QApplication(sys.argv)


# rest of the code
db = QSqlDatabase.addDatabase("QMYSQL")

db.setHostName ( db_host )
db.setUserName ( db_user )
db.setPassword ( db_passwd )
db.setDatabaseName ( db_db )
db.setPort ( db_port )

db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1")
db.open()

defaultDB = QSqlDatabase.database()
query = QSqlQuery("SELECT * FROM Users")

qe = query.exec_()
print "query exec" , query.exec_()
if not qe:              # if error
    print QSqlQuery.lastError( query ).text()
else:                   # else display returned values
    while query.next():
        print "query value" , query.value(0).toString()


db.close()