2

I tried this code from the MySQL reference but it crashes when it comes to the point mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");. Does somebody has a working exmaple for a embedded server?

#include <mysql.h>

static char *server_options[] = {"mysql_test", "--defaults-file=my.ini", NULL};
int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
static char *server_groups[] = {"libmysqld_server", "libmysqld_client", NULL};

int main(int argc, char *argv[])
{
    QSqlDatabase mydb;
    MYSQL *mysql;

    mysql_library_init(num_elements, server_options, server_groups);
    mysql = mysql_init(NULL);
    mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
    mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);

    mysql_real_connect(mysql, NULL, NULL, NULL, "database1", 0, NULL, 0);

    mydb = QSqlDatabase::addDatabase("QMYSQL", "con1");

    mydb.setDatabaseName("database1");

    if(!mydb.open())
    {
        qDebug() << mydb.lastError();
    }

    mysql_library_end();
    return 0;
}

1 Answer 1

1

Use this line of code before mysql_real_connect().

mysql_init(mysql);
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP,"your program name"); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.