1
I have the following C code that connects to a mysql database and performs a query:
#include <mysql.h>
#include <stdio.h>
int main(void){
MYSQL Connection;
MYSQL_RES *res;
MYSQL_ROW row;
mysql_init(&Connection);
if(mysql_real_connect(&Connection, "127.0.0.1", "root", "xururuca", "test", 0, NULL, 0)){
printf("Connection: Ok...\n\n");
}else{
printf("Error in connection\n\n");
}
mysql_query(&Connection ,"select id from accounts where username='Alan' and password='lixodoesgotogostoso';");
res=mysql_store_result(&Connection);
row=mysql_fetch_row(res);
printf("%s\n", row[0]); //ele imprime 3 (Ok...)
int userID=row[0]; //Agora tento passar esse 3 para uma variável do tipo int...mais não rola
printf("%d\n", userID); //Imprime lixo e não 3 que seria o correto
mysql_free_result(res);
mysql_close(&Connection);
return 0;
}
When compiling: Warning: initialization makes integer from Pointer without a cast [-Wint-Conversion]|
So, I want my 'result set' to go to the userid variable, more as I do it without major problems?