I am trying to write a program in C using the MYSQL C API. I have everything working, except recently I have been getting an error when trying to connect to a server. No matter what server I connect to, it continues to give me "mysql server has gone away.". My goal is basically to access an external server and retrieve some data. Here is the code that I have so far:
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
printf("%s",mysql_stat(conn));
fprintf(stderr, "%s\n", mysql_error(conn));
} else {
printf("works");
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
}
if (mysql_query(conn, ...orif (! mysql_query(conn, ...? – ypercubeᵀᴹ May 12 '11 at 7:21