14 December 2011

Getting MySQL tables names in PHP.

Source code viewer
  1. $schema = array();
  2. $host = 'localhost';
  3. $username = 'root';
  4. $password = '';
  5. $link = mysql_connect($host, $username, $password);
  6. if ($link) {
  7. $result = mysql_query('SHOW TABLES FROM '.mysql_real_escape_string('database_name'), $link);
  8. while ($row = mysql_fetch_row($result)) {
  9. $schema[] = $row[0];
  10. }
  11. mysql_close($link);
  12. }
  13. print_r($schema);
Programming Language: PHP