#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

#include "mysql.h"

using namespace std;

int main(int argc, char** argv)
{
    int nRC = 0;
    MYSQL*   pMySQL = NULL;
    my_bool  bReconnect = 1;
    MYSQL_RES *pRes;

    pMySQL = mysql_init(NULL);
    mysql_options(pMySQL, MYSQL_OPT_RECONNECT, &bReconnect);

    if( mysql_real_connect( pMySQL, "127.0.0.1", "root", "",
                            NULL, 3306, NULL, 0) != NULL    )
        while(true) {
            if( (nRC = mysql_query(pMySQL, "SELECT 'hello world'")) == 0) {
                pRes = mysql_store_result(pMySQL);
                mysql_free_result(pRes);
                cout << "Query ok...." << endl;
            }
            else
                cout << "Query error, code: " << nRC
                     << ", msg: " << mysql_error(pMySQL) << endl;
            usleep(4000);
        }
    else
        cout << "Unable to connect to mysqld" << endl;

    mysql_close(pMySQL);

    return 0;
}
