mySQL with C++

Dec 14, 2011 at 9:44am
Hi all,

How do i get a value from a certain field from a database and assign it to a variable in my program? Is it something like :

MYSQL *conn;
mysql_query(conn, "SELECT Filter FROM setting");

char filter_exp = mysql_query(conn, "SELECT Filter FROM setting;");

I want to actually obtain the value of the field filter.
Read in the value and assign it to
char filter_exp


How do i do it?
Dec 14, 2011 at 6:03pm
MySQL and C++?

No. It's possible if you find some kind of MySQL C++ library, or try making one yourself... but don't do that, especially the latter, unless your program absolutely MUST breathe the SQL puke. Once you're able to read the database, please convert it to a better format. Then drop SQL and have a nice day.

I recommend you create your own "database" system in C++. But do you actually need a database that rigerous, or are you just trying to save/load simple data about a file system?


Well to start:

IOstream is a nice library for input/output operations (including files) as you being a beginner, although I prefer to use regular C (stdio), personally.

http://cplusplus.com/reference/iostream/

You'll also probably like using C++ strings and STL containers/algorithms for handling data.

http://cplusplus.com/reference/string/
http://cplusplus.com/reference/stl/
http://cplusplus.com/reference/algorithm/


But to sum it up, I think SQL is absolutely horrible by all means: cumbersome by structure and poorly designed overall. You're better off without it.


This is SPARTA C++ !
Not PHP.
Last edited on Dec 14, 2011 at 6:40pm
Dec 14, 2011 at 8:17pm
I would check out the MySQL c++ Connector, on the MySQL website. I recommend building it first. It's easy to use and allows you to do exactly what you need. They have plenty of examples there. Better yet, try using the QSqlDatabase from the Qt Framework. This is far superior, but of course more bulk. The poster before me is being just a little harsh and is obviously biased against SQL in general. MySQL and c++ work fine together, you just need a good library.
Last edited on Dec 14, 2011 at 8:18pm
Dec 14, 2011 at 10:02pm
Hehe yeah I was a little harsh. ;)
Topic archived. No new replies allowed.