Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Program communicating with MySQL Database

Tags:

c++

mysql

Does anyone know of a simple way for a C++ program to communicate directly with a MySQL database? I have looked at MySQL++ and found it to be very confusing. If anyone knows of a very simple way of doing this, please let me know.

Thanks

P.S. I am developing on a Windows machine. PHP and MySQL web web application setup. C++ setup to talk to the serial port. Thus why I need a way for C++ to talk to the MySQL database directly.


1 Answers

There are quite a few database API wrappers but my favourite - and the one I recommend - is the SOCI library. Much nicer syntax than using the raw C API.

The 'motivating' example from the SOCI website:

int id = ...;
string name;
int salary;

sql << "select name, salary from persons where id = " << id, into(name), into(salary);
like image 157
MattyT Avatar answered Oct 20 '25 22:10

MattyT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!