Qt and MySQL C API
-
Hi, I'm using MySQL C connector to connect to my database. My tables are in UTF-8 format. When I try to read my data I haven't right output. Here is my code:
@my_ulonglong rows;
mysql_query(&conn, command.toAscii().data());
res = mysql_store_result(&conn);
QList<QList<QString> > vysledok;
int i;
QList<QString> riadok;
while ((row = mysql_fetch_row(res)) != NULL) {
riadok.clear();
for (i = 0; i < rows; i++) {
QString temp;
temp = QString::fromUtf8(row[i]);
qDebug() << temp;
}
}
mysql_free_result(res);
return vysledok;@
And my screen with debug error is here:
!http://mksoft.marconet.sk/mysql_debug.jpg(Output)!My application output is:
@Debugging starts
"1"
"Administrator"
"Website administrator"
"??01??0????????0??0??0?+1?2"
Debugging has finished@ -
Hi Sibyx,
You can try this code:
mysql_init(&mysql);
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "utf8");
mysql_options(&mysql, MYSQL_INIT_COMMAND, "SET NAMES utf8");mysql_real_connect(&mysql,CTH_SERVER,CTH_USER,CTH_PASSWORD,CTH_DB_IN,0,0,0));
:)