Skip to content

rktuxyn/mysqlw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multi Connection Pool MySQL C++ Wrapper for web_jsx (FCGI/CGI Application)

#Include header file

#include <my_sql.h>

Initilize my_sql instance

my_sql* sql = new my_sql();

Create connection detail

connection_details* con = new connection_details();
con->database = new std::string("test");
con->host = new std::string("localhost");
con->user = new std::string("root");
con->password = new std::string("*****");
con->unix_socket = NULL;
con->port = 0;
con->clientflag = 0;

Connect MySQL with this connection detail

if (sql->connect( con ) == connection_state::CLOSED) {
	std::cout << sql->get_last_error();
}

Drop Database

mysql->execute( 'DROP DATABASE IF EXISTS web_jsx_db' );

Create Database

mysql->execute( 'CREATE DATABASE IF NOT EXISTS web_jsx_db' );

Switch Database

mysql->switch_database("web_jsx_db");

Execute plain sql statement

sql->execute("CREATE TABLE IF NOT EXISTS Persons ( PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255), City varchar(255))");

Read the status of current execution

if ( sql->has_error() ) {
  std::cout << sql->get_last_error();
}

Return query result

const char* ret = sql->execute('select Address from Persons limit 1');

Execute plain sql statement as like as data reader

int ret = sql->execute(select * from Persons, [](int index, std::vector<char*>& rows) {
	for (std::vector<char*>::iterator i = rows.begin(); i != rows.end(); ++i){
		std::cout << *i;
	}
	return;
});

if ( ret < 0 ) {
	std::cout << sql->get_last_error();
}

Close all connection pool

sql->close_all_connection();

Clear MySQL all connection pool and instance

sql->exit_all();