#include #include #include "/usr/local/include/mysql/mysql.h" void main(void) { MYSQL *sql; MYSQL_RES *r; MYSQL_ROW row; int num_fields, i, j, notok; char *mypassword="xxxxxxxxxx"; printf("Put your correct password in the program, then you can\n"); printf("delete this printf statement.\n"); sql=mysql_real_connect(NULL, NULL, NULL, mypassword, 0, NULL, 0); if (sql==NULL) { printf("Failed to connect to server\n"); exit(1); } notok=mysql_select_db(sql,"class"); if (notok) { printf("mysql_select_db failed: %s\n", mysql_error(sql)); exit(1); } else printf("selected database ok\n"); r=mysql_list_tables(sql, NULL); if (r==NULL) { printf("mysql_list_tables failed: %s\n", mysql_error(sql)); exit(1); } num_fields=mysql_num_fields(r); if (num_fields!=1) { printf("Something funny here!\n"); exit(1); } while (1) { row=mysql_fetch_row(r); if (row==NULL) break; printf("Table: %s\n", row[0]); } mysql_free_result(r); notok=mysql_query(sql, "select * from people where state='UT'"); if (notok) { printf("mysql_query failed: %s\n", mysql_error(sql)); exit(1); } else printf("query accepted: %s\n", mysql_info(sql)); r=mysql_store_result(sql); if (r==NULL) { printf("mysql_store_result failed: %s\n", mysql_error(sql)); exit(1); } printf("Utah Residents:\n"); j=0; num_fields=mysql_num_fields(r); while (1) { row=mysql_fetch_row(r); if (row==NULL) break; j+=1; printf(" %2d: _", j); for (i=0; i