View Full Version : MySQL database ,Garbled

5th June 2009, 11:42
I create a mysql database in my application,and it is name with Chinese.

QString dataBaseDir=mysqlDir+DatabaseName;//DatabaseName(In Chinese)

When I connect the database,I get the following error:Unknown database '????' QMYSQL:Unable to connect.Please help me.

5th June 2009, 12:03
Unknown database '????'
Seems you have a problem with the right text encoding. And your code have nothing to do with a database. Its creating a directory, so could you post the relevant code?

5th June 2009, 14:47
This is all the codes about creating a mysql database(Because it create a directory in the mysqlInstallDir\Data\).The following code is to connect the database.

QSqlDatabase defaultDB = QSqlDatabase::addDatabase( DB_DRIVER );
defaultDB.setDatabaseName( DatabaseName);
defaultDB.setUserName( DB_USER );
defaultDB.setPassword( DB_PASSWD );
defaultDB.setHostName( DB_HOST );
if ( defaultDB.open() )
return true;

5th June 2009, 15:13
Fine, and what value has DatabaseName? How do you set the value of that variable and what encoding has your *.cpp file?

6th June 2009, 08:07
1.the value of DatabaseName is delivered by the GUI,and it is written in Chinese.
2.Sorry,I don't know how to find the encoding of my *.cpp file.

8th June 2009, 04:46
help me,please.

9th June 2009, 05:38
Who can help me?Please.

9th June 2009, 15:24

the error is in the encoding, but without any specific informations it is hard to say. So run some tests:

create a database with only asci letters as name
try to connect via your interface to that database.

-> If that works, then try different encodings of your QString, when setting the database name for the connection. toLocal8Bit(), utf16()... Try to hardcode, maybe your database does not support database names in utfX