-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
51 lines (50 loc) · 1.41 KB
/
query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
include_once "config.php";
if(isset($_GET["table_name"]))
{
$host = $constring;
$username = $uname;
$password = $pword;
try {
$pdo = new PDO($host, $username, $password);
$q = "SELECT * FROM " . $_GET["table_name"] . " limit 10";
$out = $pdo->query($q);
if($out === false)
{
echo "Unable to execute this - <code>" . $q . "</code> Query";
return;
}
// echo "<pre>";
$count = true;
$table = "<table class=\"table table-striped table-hover \"><thead><tr>";
foreach($out->fetchAll() as $item) {
if($count)
{
foreach(array_keys($item) as $key)
{
if(gettype($key) != "integer")
{
$table .= "<th>$key</th>";
}
}
$count = false;
$table .= "</tr></thead><tbody>";
}
$table .= "<tr>";
foreach ($item as $k => $v) {
if (gettype($k) != "integer") {
$table .= "<td style='width: 10%'>$v</td>";
//echo "<br />";
}
}
$table .= "</tr>";
}
$table .= "</tbody></table>";
//echo "</pre>";
echo $table;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}