Connecting to MySQL database with C++

Started by
2 comments, last by Antheus 16 years, 11 months ago
I am creating a project management system and the intiial version is going to have a PHP based interface. What would be nice is to also offer a C++ interface however i can't seem to find a libraries to help with connecting and queries a MySQL database. anyone know of any libraries of tutorials on how to do this?
Advertisement
MySQL C API.

http://dev.mysql.com/doc/refman/5.0/en/c.html

Yes, it's C API.

There's various C++ ports, wrappers, etc., but I found them all either: Useless, abandoned, obsolete, too bulky or not-offering-enough.

So in the end, I ended up using the MySQL provided one, which is always up to date and regularly maintained, and can be easily integrated into C++. This way I also have a nice choice between low ( by library ) and high-level (my API) level access to the database.

The only major hurdle with this library is thread safety, but that one can easily be solved.

Quote:The only major hurdle with this library is thread safety, but that one can easily be solved.

Out of curiosity, how?
I've got my own wrapper around this lib, that amongst other things makes it thread safe.
Is there a better approach?
Quote:Original post by eq
Quote:The only major hurdle with this library is thread safety, but that one can easily be solved.

Out of curiosity, how?
I've got my own wrapper around this lib, that amongst other things makes it thread safe.
Is there a better approach?


No, there isn't.

The C API and some pre-compiled libs as provided might not be thread-safe.

So in order to use it, you need to first build thread safe libraries, and then use them in thread safe manner.

For example, a connection, while thread-safe by implementation, may not be used cuncurrently by several threads.

This comes from the fact that from logical perspective, concurrently using a connection doesn't make sense. Creating a query, filling the buffers, sending it, waiting for response, and processing the response needs to be done in order, or the results are undefined.

The design of the API simply isn't concurrent in any way, although the implementation itself is.

A true concurrent design would use some different aproach, callbacks, or similar. But current implementation requires you to ensure that each connection executes only one query at a time.

This topic is closed to new replies.

Advertisement