C++ and MySQL interface

Hi

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.

Can anyone point me in the right direction?

The header files should be from the pacakge mysql-devel or perhaps libmysqlclient-devel, check YaST. They are C header files, but have the usual:

!#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif

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.

Hi,

as ken_yap already mentioned, you can use the MySQL-C API but it is not object orientated but well documented on the reference manual MySQL :: MySQL 5.1 Reference Manual :: 21.8.2 C API Function Overview.

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).

Hope this helps

aescott wrote:

> 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.

> Can anyone point me in the right direction?

Install the devel packages you need?


Ruurd

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:

ldconfig

Sorry about the omission.

I tryied it with mysql+±3.0.9, but didn’t work. I got the next answers:

make

make: *** No targets specified and no makefile found. Stop.

sudo make install

make: No rule to make taeget ‘install’. Stop.

Hi,

can you be more specific what you’ve tried, e.g. did you try to compile mysql++ from source or compile your application which uses mysql++?

Have a lot of fun

I used tarbal mysql+±3.0.9.tar.gz

Step 2) Un-archive the file in a working directory.

gzip -d mysql+±3.0.8.tar.gz = OK

tar -xvf mysql+±3.0.8.tar = OK

Step 3) Change into the directory and configure:

cd mysql+±3.0.9

./configure --prefix=/usr = OK

Step 4) Make and install
I tryied run make from the same dir mysql+±3.0.9

make

make: *** No targets specified and no makefile found. Stop.
Also from the same dir mysql+±3.0.9

sudo make install

make: No rule to make taeget ‘install’. Stop.

Post the last few lines of output from the ./configure in step 3. It seems it’s NOT ok as no Makefile was generated.

Where should I unpack mysql++?

Where should I unpack mysql++?

Anywhere convenient, under your home directories perhaps. Didn’t you do this step already?

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.

Hi,

I am interested with this.
I am basically a C++ developer, closely working for MySQL
Let me know what need to be done.

Regards
Ramaswamy B.A
rotfl!