OSDN Git Service

4dd3d9c9145acc3e995f6bf7f4ca65ab1651ed59
[opengatem/opengatem.git] / phpsrc / showtable.php
1 <html>
2 <head>
3 <title></title>
4 </head>
5 <body>
6
7 <h2>Show Tables</h2>
8 <p>
9 <a href='showtable.php?table=macaddrs'>macaddrs</a> 
10 <a href='showtable.php?table=sessionmd'>sessionmd</a> 
11 <a href='showtable.php?table=sessionview'>sessionview</a> 
12 <a href='showtable.php?table=nicvendors'>nicvendors</a> <br>
13 (Show max 1000 rows of selected table).
14 </p>
15
16 <?php
17   /************************************************************/
18   // show last 1000 rows of selected database on the web page.
19   // the database connection parameters might be modified.
20   // As this script should be used only by the administrators, 
21   // it should be protected by some access control method.
22   /************************************************************/
23
24   // no table is indicated 
25   if(!isset($_GET['table']))return;
26
27   // connect and access to MySql DB
28   $link = mysqli_connect('localhost', 'root', '');
29   if (!$link) die('Cannot connect DB'.mysqli_error());
30    
31   $db_selected = mysqli_select_db($link, 'opengatem');
32   if (!$db_selected) die('Cannot select DB'.mysqli_error());
33    
34   mysqli_set_charset($link, 'utf8');
35    
36   $result = mysqli_query($link, 'SELECT * FROM '.$_GET['table'].' limit 1000');
37   if (!$result) die('Fail query'.mysqli_error());
38    
39   // print header
40   print("<table border=1>");
41   print('<tr>');
42   $count=0;
43   while ($field = mysqli_fetch_field($result)) {
44     print('<td>'.$field->name.'</td>');
45     $count++;
46   }
47   print('</tr>');
48
49   // print rows
50   while ($row = mysqli_fetch_row($result)) {
51     print('<tr>');
52     for($i=0; $i<$count; $i++){
53       print('<td>'.$row[$i].'</td>');
54     }
55     print('</tr>');
56   }
57   print("</table>");
58   $close_flag = mysqli_close($link);
59
60 ?>
61
62 </body>
63 </html>