
using namespace std;
#define DATABASE_NAME  "robotank"
#define DATABASE_USERNAME "root"
#define DATABASE_PASSWORD "robotank"
#define SERVER "localhost"
// MYSQL *conn;

MYSQL *conn = {};  // this is the main connector
MYSQL *conn2 = {};  // this connector is used to save ds18b20 and probe data
MYSQL *conn3 = {};  // this connector is used to save chart data

void connectMysql (void)  // this is the main connector
{
        // std::cout << conn << endl;
     //initialize MYSQL object for connections
    conn = mysql_init(NULL);
        // std::cout << conn << endl;

    if(conn == NULL)
    {
        // std::cout << "connectMysql Failed  - " << endl;
        // fprintf(stderr, "ABB : %s\n", mysql_error(conn));
        return;
    }

    //Connect to the database
    if(mysql_real_connect(conn, SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, 0, NULL, 0) == NULL)
    {
        // std::cout << "connectMysql Failed 2  - " << endl;
        // fprintf(stderr, "%s\n", mysql_error(conn));
    }
    else
    {
        mysql_commit(conn);
        //  printf("Database connection successful.\r\n");
    }
}

void mysql_disconnect (void)
{
    mysql_close(conn);
    // mysql_free_result(conn);
    //  printf( "Disconnected from database.\r\n");
}

void connectMysql2 (void)  // this connector is used to save ds18b20 and probe data
{
    conn2 = mysql_init(NULL);
    if(conn2 == NULL) {return;}
    if(mysql_real_connect(conn2, SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, 0, NULL, 0) == NULL) {
        // std::cout << "connectMysql2 Failed 2  - " << endl;
    }
    else {mysql_commit(conn2);
        //  printf("Database 2 connection successful.\r\n");
    }
}

void mysql_disconnect2 (void)
{
    mysql_close(conn2);
}

void connectMysql3 (void)  // this connector is used to save chart data
{
    conn3 = mysql_init(NULL);
    if(conn3 == NULL) {return;}
    if(mysql_real_connect(conn3, SERVER, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, 0, NULL, 0) == NULL) {
        // std::cout << "connectMysql3 Failed 2  - " << endl;
    }
    else {mysql_commit(conn3);
        //  printf("Database 3 connection successful.\r\n");
         }
}

void mysql_disconnect3 (void)
{
        //  printf("Database 3 closed.\r\n");
    mysql_close(conn3);
}