I’m trying to use C++ to access a MySQL database. I’m new to C++, although I’ve been coding in Java for a while and can make the connection with the database in Java.
I’ve found various solutions on the net, but none work. I seem to be missing some C++ headers (mysql++.h, connection.h and so on) - I would have thought that these would have been installed automatically with YaST and the MySQL implementation (xampp - Apache, MySQL and PhP).
If necessary, I can remove xampp and install the various components separately, but I’d appreciate some advice that this would give me the desired result.
brackets to make the C prototypes suitable for C++. This doesn’t make the API object oriented, it just tells C++ that the functions in the mysql library are C functions and so should use C linkage.
But there is also the possibility to use a higher level interface to MySQL you can use Qt libraries by using the QtSql module for that which is easier to use than the C-API have a look at Qt 4.3: QtSql Module (it is possible to use the QtCore libraries without a gui application).
> missing some C++ headers (mysql++.h, connection.h and so on) - I would
> have thought that these would have been installed automatically with
> YaST and the MySQL implementation (xampp - Apache, MySQL and PhP).
No why? The majority of users don’t need them. Developers need them if they want to program against it.
The header file you are using is from a library called MySQL++. MySQL++ is not included in the openSUSE repositories. However, do not despair - fixing this is quite easy.
Step 1) Visit this web site and download the latest source file (currently 3.0.8): MySQL++
Step 2) Un-archive the file in a working directory.
gzip -d mysql+±3.0.8.tar.gz
tar -xvf mysql+±3.0.8.tar
Step 3) Change into the directory and configure:
cd mysql+±3.0.8
./configure --prefix=/usr
Step 4) Make and install
make
sudo make install
You should now be able to use this library. Let me know if you have any problems.
This is much for myself as everyone else… I recently had to re-build this and it occurs to me that I left a step off. After doing everything defined above, run ldconfig as root:
OK, I did it and it’s working now. I try read some data from MySQL database from c++ program with mysql++ api and compile was successful and program works corect.
Thanks a lot.