This post has already been read 5532 times!

MySQL++ is a C++ wrapper for MySQL’s C API. It is built around the same principles as the Standard C++ Library, to make dealing with the database as easy as dealing with STL containers. In addition, MySQL++ provides facilities that let you avoid the most repetitive sorts of SQL within your own code, providing native C++ interfaces for these common tasks.

Check this web page and download the latest source code: http://www.tangentsoft.net/mysql++

mysql++-3.2.1.tar.gz (2.2 MB, 2013.12.10) — Library source code

wget http://www.tangentsoft.net/mysql++/releases/mysql++-3.2.1.tar.gz
tar xvfz mysql++-3.2.1.tar.gz
cd mysql++-3.2.1.tar.gz
./configure
make
make install

After mysql++ installation you will see the following message :

sudo make install
mkdir -p /usr/local/lib
/usr/bin/install -c -m 644 libmysqlpp.so /usr/local/lib
/usr/bin/install -c libmysqlpp.so.3.2.1 /usr/local/lib
(cd /usr/local/lib ; rm -f libmysqlpp.so libmysqlpp.so.3; ln -s libmysqlpp.so.3.2.1 libmysqlpp.so.3; ln -s libmysqlpp.so.3 libmysqlpp.so)
mkdir -p /usr/local/include/mysql++
(cd . ; /usr/bin/install -c -m 644  lib/*.h /usr/local/include/mysql++)

For a easy use of MySQL++ I sugest to make the following operations :

1. Copy the mysql++ from /usr/local/include/mysql++ to /usr/include/mysql++

sudo cp -r /usr/local/include/mysql++ /usr/include

2. Copy the libmysqlpp.so libmysqlpp.so.3 libmysqlpp.so.3.2.1 from /usr/local/lib to /usr/lib64(for x86_64 configurations)

sudo cp * /usr/local/lib /usr/lib64

3. Then use MySQL++ in C++ with Eclipse with the following settings :

C/C++ Build->Settings->GCC C++ Compiler->Includes
Include paths (-l)
/usr/include/mysql 
/usr/include/mysql++

mysqlplusplus_eclipse

C/C++ Build->Settings->GCC C++ Linker->Libraries
Library search path(-L)
/usr/lib64/mysql

mysqlplusplus_eclipse_links1

C/C++ Build->Settings->GCC C++ Linker->Miscellaneous
Linker flags : -lmysqlpp -lmysqlclient
Other options(-Xlinker [option])
-lmysqlpp
-lmysqlclient

mysqlplusplus_eclipse_links2

I post here a little example with a MySQL++ connexion made in Eclipse with the required settings.
mysql++_connexion.cpp

#include <iostream> 
#include <mysql++.h>
#include "database.h"

using namespace std;
using namespace mysqlpp;
using namespace Database;

int main(int argc, char* argv[]) {

	// create the database object
	MW_DATABASE database;

	if( database.connectDatabase("database","localhost","root","",3306) )
	{
		cout << "Database connexion SUCCESS..." << endl;
	}
	else {
		cout << "Database connexion error" << endl;
	}

	return 0;
}

database.h

namespace Database {

	class MW_DATABASE {

		protected :
			bool connected;
			unsigned int port;
			const char* host;
			const char* database;
			const char* username;
			const char* password;

		public :
			bool connectDatabase(const char* database, const char* host, const char* username, const char* password, unsigned int port);

	}; //end class MW_DATABASE

}//end namespace Database

database.cpp

#include <iostream>
#include <errno.h> 
#include <mysql++.h>
#include "database.h"

using namespace std;
using namespace mysqlpp;

namespace Database {

	bool MW_DATABASE::connectDatabase(const char* database, const char* host, const char* username, const char* password, unsigned int port){

		bool thereturn;

    	try {
    		Connection conn(use_exceptions);
    		thereturn = conn.connect(database, host, username, password, port);
    	}

        // Handle any query errors
    	catch (const BadQuery& er)
	    {
	        cerr << "Query error : " << er.what() << endl;
	        thereturn = false;
	    }

	    // Catch-all for any other MySQL++ exceptions
	    catch (const Exception& er) {
	        cerr << "MySQL++ error : " << er.what() << endl;
	        thereturn = false;
	    }

		return thereturn;
	}//end method connectDatabase

}//end namespace Database

The sources for MySQL++ project with Eclipse
mysql++_connexion.tar

Comments are closed.

Post Navigation