1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <string>
#include <mysql.h>
using namespace std;
int mysql_verify(int i);
int main()
{
MYSQL *my;
string id,info;
int j;
ifstream infile("mytext.txt");
getline(infile,id);
getline(infile,info);
infile.close(infile);
j = mysql_verify(id.c_str());
.
.
.
.
/** and so on;**/
}
int mysql_verify(int id)
{
MYSQL *my;
my = mysql_init(NULL);
if(my == NULL)
{
sprintf(error,"%s", mysql_error(my));
cout<<"mysql: "<< error<<"\n";
exit (1);
}
if(mysql_real_connect(my,myserver,myuser,mycpass,mydatabase,myport,NULL,0) == NULL )
{
sprintf(error,"%s",mysql_error(my));
cout<<"mysql: "<<error<<"\n";
exit (1);
}
char que[30];
sprintf(que,"select * from smytable where id = \"%s%s\"\n",(mydcID).c_str(),id);
if(mysql_query(my,que)){
sprintf(error,"Mysql: %s\n",mysql_error(my));
cout<<error;
mysql_close(my);
exit (1);
}
MYSQL_RES *res = mysql_store_result(my);
i = mysql_num_rows(res);
if( i > 1 )
{
cout<<"There are "<<i << " elements with ID: "<<myconn.dcID<<id<<"\n";
mysql_close(my);
exit (1);
}
mysql_close(my);
return i;/***GDB says here is the problem**/
}/*****and also GDB says that the problem is here******/
|