PDA

View Full Version : Problems with QODBC and MySQL



crazymonkey
25th April 2011, 13:34
So I have MySQL running and want to interface with it through ODBC, I have ODBC for mysql installed and configured under my windows data sources (using Windows 7 btw)
when I try to run the following code:

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("root");
db.setPort(3306);
db.setPassword("xxxxxx");
qDebug() << db.isValid();
if (!db.open()) cout << "Failed to connect to root mysql admin";
//!db.open() always returns true so something is wrong

I get
"Failed to connect to root mysql admin"

I have also tried running
qDebug() << << QSqlDatabase::drivers();

and it returns <QSQLITE, QODBC, QODBC3>

What could be wrong?

Added after 1 22 minutes:

nevermind, the PC am using had mysql for x64, but my connector was for x86, so there was an architecture mismatch, simply removing the x86 connector and installing the x64 one fixed these issues.