Read records returned by execute_query from MySQL in C

unsigned int dump_records(MYSQL *mysql, MYSQL_RES *recordset) { MYSQL_ROW row; int i; unsigned int num_fields; recordset = mysql_store_result(mysql); if (recordset) { printf(“Get some recordsn”); row = mysql_fetch_row(recordset); while (row != NULL) { for (i=0; i < mysql_num_fields(recordset); i++) { if (i > 0) fputc('t', stdout); printf(“%s, row[i] != NULL ? row[i]: “NULL”); } fputc('n', stdout); row … Continue reading Read records returned by execute_query from MySQL in C

DBCommon.c – Connect to a MySQL database in C

DBCommon.c MYSQL *do_connect (char *host_name, char *user, char *password, char *db_name) { conn = mysql_init(NULL); if (conn == NULL) { print_error(conn, “mysql_init() failedn”); return (NULL); } if (mysql_real_connect(conn, host_name, user, password, db_name, 0, NULL, 0) == NULL) { print_error(conn, “mysql_real_connect() failed”); return(NULL); } return (conn); } void print_error(MYSQL *conn, char *message) { fprintf(stderr, “%sn”, message); … Continue reading DBCommon.c – Connect to a MySQL database in C