PHP/MySQL Database/mysql list tables

Материал из Web эксперт
Перейти к: навигация, поиск

Listing Tables

   <source lang="html4strict">

<?php $conn = @mysql_connect( "localhost", "userName", "password" ) or die( "Sorry - could not connect to MySQL" ); $rs1= mysql_list_dbs( $conn ); for( $row=0; $row < mysql_num_rows( $rs1 ); $row++ ) {

 $this_db = mysql_tablename( $rs1, $row );
 $list .= "".$this_db."
"; if( $this_db != "mysql" ) { $rs2 = mysql_list_tables( $this_db ); for( $num=0; $num < mysql_num_rows( $rs2) ; $num++ ) { $list .= " - " . mysql_tablename( $rs2, $num ) . "
"; } }

} ?> <html>

<head>
 <title>Listing Tables</title>
</head>
<body> 
 <?php  echo( $list ); ?> 
</body>

</html>

 </source>
   
  


mysql_list_tables.php

   <source lang="html4strict">

<?php

  mysql_connect("localhost","root","");
  $tables = mysql_list_tables("mydatabase");
  while (list($table) = mysql_fetch_row($tables))
  {
     echo "$table 
"; }

?>

 </source>