How to use database in Cocos2d-x

How to use database in Cocos2d-x
0.0 0


Hi all,

I’m a newbie in Cocos2d-x. How can I store the database? Which database can support all platforms (android, ios, windows phone, win32, web, etc)?

It’s very nice if you can give me a detail tutorial or examples to use database in Cocos2d-x.

Thanks all


you can use sqlite and wrapper for it if you don’t like C API.
Wrapper: easySQLite.

You can use any database engine it only must be in C/C*+ cocos2dx gives you path where you can save your database.
So please don;t search about database for cocos2dx simply look for database libs in C/C*+ :slight_smile:

I suggest you to use SQLite because this is most popular :slight_smile: and also in 1 file. Also cocos has it in extensions path?


Yes, sqlite3 is in external folder of cocos2d-x.

Saving user data

Great, thank you so much. I’ll try with Sqlite3


If you just want to store values in a persistent way, you are able to use sharedUserDefault

Example usage:
CCUserDefault::sharedUserDefault()->setIntegerForKey("localGamesLost", 0);
get with default value if the key do not exist:
CCUserDefault::sharedUserDefault()->getIntegerForKey("localGamesLost", 0);



UserDefault is simple but not a good way to save game data.
Sqlite3 is better


sqlite3 is very easy to use and you can add encryption, read-only db, compression, etc.

transactions, pre-compiled procedures, strongly typed data, metadata … etc…


Regarding the encryption…
For encryption you have to use a key, where or how do you store it in a secure way?


I hope I can help u in this topic


Thank you so much :smiley:

yuye liu wrote:

I hope I can help u in this topic