Codeblocks MySQL Tutorial

Code::Block is an open source C++ IDE built to meet the complicated development aims of the users. It is developed to be very extensible and configurable. The IDE has the following features: rapid custom build system, support for parallel builds, multi-target projects, user-defined watches, call stack, switch between threads, class browsing and smart indent. MySQL is a popular open source database management system. You can connect to MySQL database in Code::Block and manipulate the data such as retrieve, update, insert and delete.

...
You can conenct to MySQL and manipulate its data in Code::Blocks.

Step

Download Code::Blocks setup file from its official website (see resources.) Double-click the setup file to start the installation. Follow the installation wizard until completion.

Step

Double-click the Code::Blocks icon to enter the development interface. Click “Settings,” “Compiler and Debugger” and “Linker Settings.” Click “Link Library” tab to open the dialog window. Click “Add” button and input “/usr/lib/libmysqlclient.so.”

Step

Click “Settings,” “Compiler and Debugger” and “Search directories.” Select “Compiler” and input “/usr/include/mysql.” The development environment with MySQL is properly configured.

Step

Include the following files in your application:

Step

#include#include

Step

Connect to MySQL using the MySQLManager function:

Step

MySQLManager::MySQLManager(string hosts, string userName, string password, string dbName, unsigned int port)
{
IsConnected = false;
this ->setHosts(hosts);
this ->setUserName(username);
this ->setPassword(password);
this ->setDBName(database);
this ->setPort(port); }

Step

Conduct SQL queries via function runSQLCommand:

Step

bool MySQLManager::runSQLCommand(string sql)
{
mysql_real_query(&mySQLClient,sql.c_str(),(unsigned int)strlen(sql.c_str())); }

Step

Define your Main function using the said functions:

Step

int main(){ MySQLManager sqlres("127.0.0.1","root","search1","HR",3306); sqlres.initConnection(); sqlres.runSQLCommand("select * from employee"); sqlres.destroyConnection(); return 0; }