Often the database itself provides an API for its access in C/C++. But it often consists of using confusing callback functions (callbacks are fun though) and the process differs from database to database. Solution? Use a wrapper..
This wrapper seems particularly interesting.. http://www.alhem.net/project/mysql/index.html
Download the wrapper source code, compile and install.
# make install
Using the database using this wrapper is as easy as:
Database db(“localhost”, “dbuser”, “dbpasswd”, “mydb”, &log);
printf(“Database not connected – exiting\n”);
q.get_result(“select * from player”);
long num = q.getval();
std::string name = q.getstr();
printf(“#%ld: %s\n”, num, name.c_str());
Good thing is, the same code can also be used for SQLite (my fav) and ODBC too (although with different wrapper and minor modifications). Another advantage is, the wrapper is cross platform, works on both win & *nix.