OSDN Git Service

263347f061ca4334095df0692480a14c4cf9b1f0
[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   // check basic auth
19   if(getenv('REMOTE_USER')=='')  die('Cannot get auth');
20
21   // no table is indicated 
22   if(!isset($_GET['table']))return;
23
24   // connect and access to MySql DB
25   $link = mysql_connect('localhost', 'root', '');
26   if (!$link) die('Cannot connect DB'.mysql_error());
27
28   $db_selected = mysql_select_db('opengatem', $link);
29   if (!$db_selected) die('Cannot select DB'.mysql_error());
30
31   mysql_set_charset('utf8');
32
33   $result = mysql_query('SELECT * FROM '.$_GET['table'].' limit 1000');
34   if (!$result) die('Fail query'.mysql_error());
35
36   // print header
37   print("<table border=1>");
38   print('<tr>');
39   $count=0;
40   while ($field = mysql_fetch_field($result)) {
41     print('<td>'.$field->name.'</td>');
42     $count++;
43   }
44   print('</tr>');
45
46   // print rows
47   while ($row = mysql_fetch_row($result)) {
48     print('<tr>');
49     for($i=0; $i<$count; $i++){
50       print('<td>'.$row[$i].'</td>');
51     }
52     print('</tr>');
53   }
54   print("</table>");
55   $close_flag = mysql_close($link);
56
57 ?>
58
59 </body>
60 </html>