Qt QSqlDatabase ODBC and MySQL connection
-
Hi!
I noticed, that there are many problems establishing MySQL connection using ODBC driver, and many don't want to recompile Qt with MySQL driver.
This connection is for ODBC driver 3.51! It will not work with 5.1.
Here is how it goes with ODBC:@QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
db.setDatabaseName("Port=YourPort;Server=YourServerIP;Driver={MySQL ODBC 3.51 Driver};User=YourUsername;Password=YourPassword;Database=YourDatabaseName;");@Make sure that you have correct version ( 3.51) of ODBC driver installed ( "download ":http://dev.mysql.com/downloads/connector/odbc/3.51.html from MySQL website).
To open connection and print error if connetion failed:
@if(!db.open())
qDebug() << db.lastError().databaseText()@Hope it helps.
Regards,
Jake