#include #include int main() { // Connect to the MySQL database. MYSQL *conn = mysql_init(NULL); if(!mysql_real_connect(conn, "localhost", "kesavan", "password", "kesavan", 0, NULL, 0)){ printf("MySQL connection failed.\n"); }; char *query = "SELECT * FROM phonebook"; // Query the database. if (mysql_query(conn, query) != 0){ fprintf(stderr, "%s\n", mysql_error(conn)); exit(-1); } else { MYSQL_RES *results = mysql_store_result(conn); if (results) { // make sure there *are* results.. MYSQL_ROW row; while((row = mysql_fetch_row(results)) !=0){ printf("%d\t%s\t%s\n",atoi(row[0]),row[1],row[2]); } mysql_free_result(results); /* Free results when done */ } } mysql_close(conn); // Close the connection to the database. return 0; }