MySQL Forums
Forum List  »  General

Re: list of tables.
Posted by: Margaret MacDonald
Date: February 19, 2005 04:23PM

In php, which uses the C library for the mysql calls, you'd do it something like this:

$dataset = mysql_query( 'SHOW TABLES', $link_identifier ) ;
if ( ! $dataset ) { die( mysql_error() ) ; } // you don't want to continue without the list
// the dataset now has one record for each table name. Each record has only one field
while ( $record = mysql_fetch_row( $dataset ) )
{
$table_name[] = $record[0] ; // copy the name of the table into the array
}

in C, it would probably look something like this, presuming you already have your database connection set up. (I haven't written anything in C in awhile, so my syntax might not be completely correct):


char table_name[], record[] ; // I think this syntax is legal
int dataset, i ; // dataset is an integer resource identifier, like a file handle

dataset = mysql_query( 'SHOW TABLES, link_identifier ) ;
i=0 ;
while ( record = mysql_fetch_row( dataset ) )
{
strcpy( table_name[ i++ ], record ) ;
}

I hope that helps.

Options: ReplyQuote


Subject
Written By
Posted
February 18, 2005 05:20PM
February 18, 2005 05:22PM
February 19, 2005 12:13PM
Re: list of tables.
February 19, 2005 04:23PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.