// crash_report.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include #include MYSQL *conn; // the connection MYSQL_RES *res; // the results MYSQL_ROW row; // just going to input the general details and not the port numbers struct connection_details { char *server; char *user; char *password; char *database; }; MYSQL* mysql_connection_setup(struct connection_details mysql_details) { // first of all create a mysql instance and initialize the variables within MYSQL *connection = mysql_init(NULL); // connect to the database with the details attached. if (!mysql_real_connect(connection,mysql_details.server, mysql_details.user, mysql_details.password, NULL, 0, NULL, 0)) { printf("Conection error : %s\n", mysql_error(connection)); exit(1); } return connection; } MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query) { // send the query to the database if (mysql_query(connection, sql_query)) { printf("MySQL query error : %s\n", mysql_error(connection)); // exit(1); } return mysql_use_result(connection); } unsigned int __stdcall mythread(LPVOID lpParam) { // assign the results return to the MYSQL_RES pointer res = mysql_perform_query(conn,"load data local infile 'C:\\Users\\Abhishek\\Downloads\\countrylist.csv' into table `myfirst`.`csvtest1` fields escaped by ';' terminated by ',' enclosed by '?' lines terminated by '/r' (`a`, `b`, `c`, `d`, `e`, `f`, `g`, `h`, `i`, `j`, `k`, `l`, `m`, `n`)"); printf("MySQL Tables in mysql database:\n"); while ((row = mysql_fetch_row(res)) !=NULL) printf("%s\n", row[0]); /* clean up the database result set */ mysql_free_result(res); /* clean up the database link */ mysql_close(conn); return 0; } unsigned int __stdcall mythreadconnect(LPVOID lpParam) { struct connection_details mysqlD; mysqlD.server = "localhost"; // where the mysql database is mysqlD.user = "root"; // the root user of mysql mysqlD.password = "root"; // the password of the root user in mysql mysqlD.database = "myfirst"; // the databse to pick //connect to mysql conn = mysql_connection_setup(mysqlD); return 0; } int main() { HANDLE hThread1, hThread2; mysql_library_init(0, NULL, NULL); //connect in first thread hThread2 = (HANDLE)_beginthreadex(0, 0, &mythreadconnect, 0, 0, 0); WaitForSingleObject(hThread2, INFINITE); CloseHandle(hThread2); //execute in other thread hThread1 = (HANDLE)_beginthreadex(0, 0, &mythread, 0, 0, 0); WaitForSingleObject(hThread1, INFINITE); CloseHandle(hThread1); mysql_library_end(); printf("Other business in Main\n"); printf("Main is exiting\n"); getch(); return 0; }