A Simple Query Program

Now that you understand how to retrieve a resultset and check whether it was fetched without error, let's update the programs so that you can compile and run them with their new functionality.

The common.c and common.h programs are the same as before, although main.c now has more code, as shown in Listing 13.4.

Listing 13.4. main.c
 1: /* main.c */ 2: /* Connect, run a query and check the result set */ 3: 4: #include <stdio.h> 5: #include <mysql.h> 6: #include "common.h" 7: 8: #define def_db_host NULL 9: #define def_db_user NULL 10: #define def_db_name NULL 11: #define def_db_port 0 12: #define def_unix_socket NULL 13: 14: MYSQL *mysql; 15: 16: int main (int argc, char *argv[]) 17: { 18: MYSQL_RES *res_set; 19: char *db_pass; ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.