As previously I get help in Database class from U
now I want to perform following task...
1. I have One class with name "pthread" which is creating thread.the threads are simply display its number
2. I have another class with name DBconnecter it simply get connected to the database.It is used to insert data in database
NOW HERE IS MY PROBLEM START
...I want to use DBconnecter class's object in pthread class
when my pthread class perform task it must to do this work
....my pthread class is creating thread.
the thread which creating by pthread class.
they must to enter some hard coded data into database.
how can I do that?
[edit]copied from misplaced solution:[/edit]
this is my DBconnector class
#include "DBconnector.h"
#include <mysql.h>
#include <stdio.h>
#include <iostream>
MYSQL mysql,*connection;
MYSQL_RES *result;
MYSQL_ROW row;
char * ip = (char*)"192.168.49.131";
char * usr = (char*)"root";
char * pass = (char*)"admin";
char * db = (char*)"vcs";
unsigned fields;
using namespace std;
void DBconnector ()
{
mysql_init(&mysql);
connection = mysql_real_connect(&mysql, ip, usr, pass, db, 0, NULL, 0);
if (connection==NULL)
{
std::cout << mysql_error(&mysql)<< std::endl;
}
else
{
if(mysql_query(&mysql, "INSERT INTO `vcs`.`users` (`id`, `fname`, `sname`) VALUES (5, 'Rana', 'sameer')"));
else
{
result = mysql_store_result(&mysql);
fields = mysql_num_fields(result);
while((row = mysql_fetch_row (result)))
{
unsigned long *length;
length = mysql_fetch_lengths(result);
for(int i=0; i<fields; i++)
{
cout << length[i], row[i] , row[i] ;
cout << "NULL";
}
cout << endl;
}
}
}
}
namespace rumeel
{
DBconnector::DBconnector()
{
}
DBconnector::~DBconnector()
{
}
}
and this is my pthread class
#include "pThread.h"
#include <iostream>
#include <pthread.h>
#include <stdio.h>
using namespace std;
void * threadfunction (void *arg)
{
cout << "Thread Id = " << int(arg)<<endl;
return (void *) 0;
}
int main()
{
DBconnector -> DBconnector();
int j;
int value;
cout << "Enter The Number Of Threads :";
cin >> value;
for(int i=1 ; i <= value ;i++)
{
pthread_t thread;
pthread_create( &thread, NULL, threadfunction, (void*) i);
}
cin>>j;
return 0;
}
namespace rumeel
{
pThread::pThread()
{
}
pThread::~pThread()
{
}
}
sorry for poor English