How to use database in Cocos2d-x

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.

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
http://www.cocos2d-x.org/reference/native-cpp/V2.2.1/d0/d79/classcocos2d_1_1_c_c_user_default.html#ad25d8b663ab8c114c73ea876dc7b3846

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

greets

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
http://www.cocos2d-x.org/forums/6/topics/42201