Guest User

Untitled

a guest
Mar 1st, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <mysql.h>
  2. #include <stdio.h>
  3.  
  4. int main(void){
  5.  
  6. MYSQL Connection;
  7. MYSQL_RES *res;
  8. MYSQL_ROW row;
  9.  
  10. mysql_init(&Connection);
  11.  
  12. if(mysql_real_connect(&Connection, "127.0.0.1", "root", "xururuca", "test", 0, NULL, 0)){
  13.  
  14. printf("Connection: Ok...nn");
  15.  
  16. }else{
  17.  
  18. printf("Error in connectionnn");
  19. }
  20.  
  21. mysql_query(&Connection ,"select id from accounts where username='Alan' and password='lixodoesgotogostoso';");
  22.  
  23. res=mysql_store_result(&Connection);
  24.  
  25. row=mysql_fetch_row(res);
  26.  
  27. printf("%sn", row[0]); //ele imprime 3 (Ok...)
  28.  
  29. int userID=row[0]; //Agora tento passar esse 3 para uma variável do tipo int...mais não rola
  30.  
  31. printf("%dn", userID); //Imprime lixo e não 3 que seria o correto
  32.  
  33. mysql_free_result(res);
  34. mysql_close(&Connection);
  35.  
  36. return 0;
  37. }
Add Comment
Please, Sign In to add comment