SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int main(int argc, char ** argv){
  2.         MYSQL *conn;
  3.  
  4.     bddConnect(&conn);
  5. functionAddToStruct(conn);
  6. ...................
  7. }
  8.  
  9.  
  10. void bddConnect(MYSQL **conn){
  11.  
  12.     //Connexion A la bdd de facon plus sofistiquer
  13.     static char *host = "localhost";
  14.     static char *user = "root";
  15.     static char *password = "";
  16.     static char *dbname = "training_life";
  17.  
  18.     unsigned int port = 3306;
  19.     static char *unix_socket = NULL;
  20.     unsigned int flag = 0;
  21.  
  22.  
  23.     *conn = mysql_init(NULL);
  24.     if(!(mysql_real_connect(*conn, host, user, password, dbname, port, unix_socket, flag))){
  25.         fprintf(stderr, "\n Error : %s [%d]\n", mysql_error(conn), mysql_errno(conn));
  26.         exit(1);
  27.     }
  28.  
  29.     printf("Connexion Successful ! ");
  30.  
  31.  
  32. }
  33.  
  34. ------------------------------------
  35. // exemple d'utilisation :
  36. void functionAddToStruct(MYSQL *conn){
  37.  MYSQL_RES *res;
  38.     MYSQL_ROW row;
  39.  
  40.     char *sqlExercice[500];
  41.     //Afficher tout le tableau
  42.     //   for(int i;i=0;i++){
  43.  
  44.     int min=241;
  45.     int max=281;
  46.     for(int i=min;i<max;i++){
  47.  
  48.         sprintf(sqlExercice,"SELECT * FROM list_exercice WHERE id=%d",i);
  49.       //  printf("%s",sqlExercice);
  50.         mysql_query(conn,sqlExercice);
  51.         res = mysql_store_result(conn);
  52.  
  53.         while(row = mysql_fetch_row(res)){
  54.           //  printf("\n%s\t%s\n", row[0], row[1]);
  55.             if(i<min+5|| (i>min+19&&i<min+24))
  56.                 addExercice(&start2,start,row[1],row[2],"Jambe");
  57.             else if(i<min+9|| (i>min+23&&i<min+28))
  58.                 addExercice(&start2,start,row[1],row[2],"Pec");
  59.             else if(i<min+13|| (i>min+27&&i<min+32))
  60.                 addExercice(&start2,start,row[1],row[2],"Epaule");
  61.             else if(i<min+17|| (i>min+31&&i<min+36))
  62.                 addExercice(&start2,start,row[1],row[2],"Bras");
  63.             else
  64.                 addExercice(&start2,start,row[1],row[2],"Dos");
  65.         }
  66.  
  67.     }
  68.     for(int w=0;w<40;w++){
  69.         printf("\n  name : %s ------------%d------------- muscle : %s",start2->name,w,start2->muscleTest->label);
  70.         start2=start2->next->next;
  71.  
  72.     }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top