Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $is_g6 = false;
- /**
- * Created by PhpStorm.
- * User: herbe
- * Date: 20.04.2017
- * Time: 11:33
- */
- class Column
- {
- public $name;
- public $type;
- /**
- * Column constructor.
- * @param $name
- * @param $type
- */
- public function __construct($name, $type)
- {
- global $is_g6;
- $this->name = $name;
- $this->type = $type;
- $this->is_bool = false;
- if (!$is_g6 && $this->name == "g6"){
- $is_g6 = true;
- }
- if($this->type == "bool"){
- $this->is_bool = true;
- }
- }
- public function getVal($row){
- if($this->is_bool){
- if($row[$this->name]){
- return "true";
- }else{
- return "false";
- }
- }
- return $row[$this->name];
- }
- }
- $pdo = new PDO('pgsql:dbname=graphs;user=guest;password=guest;host=localhost');
- $cols = "*";
- if (isset($_GET['cols'])) {
- $cols = $_GET['cols'];
- }
- $tail = "LIMIT 500";
- if (isset($_GET['tail'])) {
- $tail = $_GET['tail'];
- }
- $stmt = "SELECT " . $cols . " FROM graph " . $tail;
- if (strpos($stmt, ';') !== false) {
- die("No injections, please, you sneaky basterd!");
- }
- $query = $pdo->query($stmt);
- $rows = $query->fetchAll();
- $columns = array();
- for ($i = 0; $i < $query->columnCount(); $i++) {
- $col = $query->getColumnMeta($i);
- $columns[] = new Column($col['name'], $col['native_type']);
- }
- //echo json_encode($result);
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Graphs collection</title>
- </head>
- <body>
- <h1>Graphs collection</h1>
- <h2>PG Query statement</h2>
- <form action="" method="get">
- <label>SELECT
- <input type="text" NAME="cols" style="width: 15em" value="<?= $cols ?>">
- </label>
- <label>FROM graph
- <textarea name="tail" style="width: 100%"><?= $tail ?></textarea>
- </label>
- <input type="submit"/>
- </form>
- <h2>Results</h2>
- <table border="1" cellpadding="5" cellspacing="0">
- <tr>
- <?php
- foreach ($columns as $column) {
- ?>
- <th><?= $column->name ?></th>
- <?php
- }
- ?>
- <?php if($is_g6){
- echo "<th>render g6</th>";
- }?>
- </tr>
- <tr>
- <?php
- foreach ($columns as $column) {
- ?>
- <th>
- <small><?= $column->type ?></small>
- </th>
- <?php
- }
- ?>
- <?php if($is_g6){
- echo "<th>-</th>";
- }?>
- </tr>
- <?php foreach ($rows as $row) {
- ?>
- <tr>
- <?php
- foreach ($columns as $column) {
- ?>
- <td><?= $column->getVal($row) ?></td>
- <?php
- }
- ?>
- <?php if($is_g6){?>
- <td>
- <a target="_blank" href="http://treedecompositions.com/#/graph/<?= urlencode($row["g6"]) ?>">SHOW</a>
- </td>
- <?php
- }?>
- </tr>
- <?php
- } ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement