Jump to content
  • Advertisement
Sign in to follow this  
RyanZec

Connecting to MySQL database with C++

This topic is 4061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!