哥哥们,小白,能帮忙写个主函数测试一下这个函数吗,老师要做,自己写出来了函数不会测试,求帮帮忙,谢谢
int mysql_login(char* id,char* password,char* rtv){
int flag = 0;//数据库连接标志 连接时为1,断开时为0
MYSQL *conn = NULL;
MYSQL s_my_connection;
MYSQL_RES *res_ptr = NULL;
MYSQL_ROW result_row;
int iRetCode = 1;
unsigned int uiTimeOut = 7; if(flag)
return 0;
conn = mysql_init(&s_my_connection);
if( !conn ){
fprintf(stderr,"mysql_init failed ! \n");
return EXIT_FAILURE;
} iRetCode = mysql_options(&s_my_connection,MYSQL_OPT_CONNECT_TIMEOUT,(const char *)&uiTimeOut);
if( iRetCode ){
fprintf(stderr,"Connection is timeout! \n");
return EXIT_FAILURE;
}
conn = NULL;
conn = mysql_real_connect(&s_my_connection,id,password,rtv,0,NULL,0);
if( conn ){
printf("MySQL Connection success!\n");
flag= 1;
}
else{
fprintf(stderr,"Connection failed!\n");
if( mysql_errno(&s_my_connection) )
{
fprintf(stderr,"Connection error %d: %s!\n",mysql_errno(&s_my_connection),mysql_error(&s_my_connection));
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
void mysql_logout( void ){
if( flag)
mysql_close(&s_my_connection);//关闭连接
flag= 0 ;
}
int mysql_login(char* id,char* password,char* rtv){
int flag = 0;//数据库连接标志 连接时为1,断开时为0
MYSQL *conn = NULL;
MYSQL s_my_connection;
MYSQL_RES *res_ptr = NULL;
MYSQL_ROW result_row;
int iRetCode = 1;
unsigned int uiTimeOut = 7; if(flag)
return 0;
conn = mysql_init(&s_my_connection);
if( !conn ){
fprintf(stderr,"mysql_init failed ! \n");
return EXIT_FAILURE;
} iRetCode = mysql_options(&s_my_connection,MYSQL_OPT_CONNECT_TIMEOUT,(const char *)&uiTimeOut);
if( iRetCode ){
fprintf(stderr,"Connection is timeout! \n");
return EXIT_FAILURE;
}
conn = NULL;
conn = mysql_real_connect(&s_my_connection,id,password,rtv,0,NULL,0);
if( conn ){
printf("MySQL Connection success!\n");
flag= 1;
}
else{
fprintf(stderr,"Connection failed!\n");
if( mysql_errno(&s_my_connection) )
{
fprintf(stderr,"Connection error %d: %s!\n",mysql_errno(&s_my_connection),mysql_error(&s_my_connection));
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
void mysql_logout( void ){
if( flag)
mysql_close(&s_my_connection);//关闭连接
flag= 0 ;
}

