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:
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
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
To copy to clipboard, switch view to plain text mode
I get
"Failed to connect to root mysql admin"
"Failed to connect to root mysql admin"
To copy to clipboard, switch view to plain text mode
I have also tried running
qDebug() << << QSqlDatabase::drivers();
To copy to clipboard, switch view to plain text mode
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.
Bookmarks