OSDN Git Service

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