OSDN Git Service

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