By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

extending mysql_list_tables or alternative

100+
P: 170
I was using a backup script I found which had

Expand|Select|Wrap|Line Numbers
  1. $tables = mysql_list_tables($database);
  2. for($i = 0; $i < mysql_num_rows($tables); $i++)
  3. {
  4.     $table = mysql_tablename ($tables, $i);
  5. ...rest of code
  6.  
It worked perfectly. However, I only want to backup particular tables. So thinking that mysql_list_tables won't let me choose certain tables, I tried using
Expand|Select|Wrap|Line Numbers
  1. $sql = "SHOW TABLES FROM $dbname like 'staff%'";
  2. $result = mysql_query($sql);
  3. $numrows=mysql_numrows($result);
  4. for($i = 0; $i < $numrows; $i++)
  5. {
  6. $row = mysql_result($result,$i,"table");
  7.     $table = $row[$i];
  8. ...rest of code
  9.  
Clearly, I don't really know what I'm doing. Can some kind person please point out my error?

Many thanks
Dec 6 '07 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821
Heya, Beary.

Try this:
Expand|Select|Wrap|Line Numbers
  1. $__tables = array('table1', 'table2', 'etc.');
  2. foreach( $__tables as $__table )
  3. {
  4.     // Do backup for table using $__table.
  5. }
  6.  
Dec 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.