Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

connection to mysql xamp



  • I have a problem with my database even if I changed the data it says that the conection is stable while the base does not exist even
    #include <QCoreApplication>
    #include <QSqlDriver>
    #include <QSqlError>
    #include <QSqlQuery>

    #include <QDebug>
    #include <QSqlError>
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("");
    db.setDatabaseName("personne");

       if(db.open())
       {
           qDebug() << "Connected";
       }else{
           qDebug() << "Connection Failed " << db.lastError();
       }
    return a.exec();
    

    }


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Connecting to a database and accessing its content are two different things.

    What exactly is your trouble here ?


Log in to reply