PDA

View Full Version : MySQL database ,Garbled



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


QString dataBaseDir=mysqlDir+DatabaseName;//DatabaseName(In Chinese)
if(!dir.mkdir(dataBaseDir)){....}

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

Lykurg
5th June 2009, 11: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?

weixj2003ld
5th June 2009, 13: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;

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

weixj2003ld
6th June 2009, 07: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.

weixj2003ld
8th June 2009, 03:46
help me,please.

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

Lykurg
9th June 2009, 14:24
Hi,

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