Hi
I'm trying to copy a value from a MySQL query result to a string pointer with no success. As soon as I call "mysql_free_result" my variable is empty! If I print the variable before "mysql_free_result" it is there! Here is a snippet of my code:
Code:
/* connect to db here */
char *name;
if (mysql_query(conn, "SELECT firstname FROM employees WHERE id = 8") != 0) {
fprintf(stderr, "%s\n", mysql_error(conn));
} else {
res = mysql_use_result(conn);
if ((row = mysql_fetch_row(res)) != NULL) {
name = row[0];
mysql_free_result(res);
printf("%s\n",name);
}
mysql_close(conn);
I don't quite understand how to copy the value to "name". I guess "name" is pointing to something that does not exist after "mysql_free_result". How do I keep the value in "name"?