[Solved]Qt remote database with MySql?
-
wrote on 10 Aug 2012, 00:35 last edited by
What is the best way to add remote MySql database connectivity.
I have attempted using the QODBC driver with no luck, I believe another issue may be that this is a shared server but believe I have the right "settings according to my host":https://my.justhost.com/cgi/help/6. I have added my ip to the remote access list also. Am i stuck building a QMySql driver because I thought the QODBC driver would work according to others.
Here is my current attempt:
@ bool CardSQL::connectSQL(void){
db = QSqlDatabase::addDatabase("QODBC");
db.setHostName("173.254.28.127");// Tried www.themindspot.com & ip with http:// and https://
db.setPort(3306);
db.setDatabaseName("dbName");
db.setUserName("dbUser");
db.setPassword("dbPass");
bool ok = db.open();
return ok;
}@I check 'ok' in a if statement and it keeps coming back failed.
-
wrote on 10 Aug 2012, 05:52 last edited by
The Qt ODBC plugin should work if you:
- Have a MySQL ODBC driver installed ( http://dev.mysql.com/downloads/connector/odbc/ ).
- Provide the name of the ODBC datasource to the QSqlDatabase::setDatabaseName(). This is not the database name ( http://www.connectionstrings.com/mysql#p31 ).
-
wrote on 10 Aug 2012, 11:41 last edited by
Built the MYSQL driver and everything works. No matter what you heart the QODBC driver isn't always sufficient. and the host string can simply be the URL (www.something.com).
-
wrote on 11 Aug 2012, 23:47 last edited by
[quote author="weblife" date="1344598910"]No matter what you here the QODBC driver isn't sufficient.[/quote]
I have personally used the QODBC driver to access MySQL. It does work as I described above.
@
#include <QtCore>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver};" "Server=newton;Port=3306;" "Database=test;User=test;Password=test"); // Or use a hybrid: // db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver};" // "Server=newton;Port=3306;" // "Database=test;"); // db.setUserName("test"); // db.setPassword("test"); // Or use a data source name (DSN) created in // ControlPanel => Administrative Tools => ODBC Connection => System DSN // db.setDatabaseName("test"); if (db.open()) { qDebug() << "Opened!"; QSqlQuery query; if (query.exec("select * from testTable")) { qDebug() << "Executed!"; while (query.next()) qDebug() << query.value(0).toString(); } else qDebug() << db.lastError(); } else qDebug() << db.lastError(); return 0;
}
@Output;
@
Opened!
Executed!
"It"
"Does"
"Work"
@ -
wrote on 13 Aug 2012, 09:20 last edited by
Sorry,
Thank you for your feedback. Edited my statement to reflect every situation. I attempted this way with no prevail, I may have done something wrong too but I have moved on with the better of the options now that I created the driver.
1/5