Name

mysql_list_tables( )

Synopsis

MYSQL_RES *mysql_list_tables(MYSQL *mysql, 
                             const char *expression)

This returns a results set containing a list of tables in the currently selected database. An expression may be given as the second argument of the function to select tables whose names match a certain pattern. The % or _ may be used as wildcards. If NULL is given for the second argument, all tables in the database will be returned.

...
MYSQL_RES *result;
MYSQL_ROW row;
...
result = mysql_list_tables(mysql, "w%");
while((row = mysql_fetch_row(result)) != NULL)
{ printf("%s \n", row[0]);  }
mysql_free_result(result);
...

This excerpt extracts a list of tables beginning with the letter “w” using the mysql_list_tables( ) function and stores the results in the result variable. Using the mysql_fetch_row( ) function, each row of the results set is stored temporarily in the row variable for printing.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.