|
@@ -0,0 +1,76 @@
|
|
|
+<?php
|
|
|
+session_start();
|
|
|
+require_once '/usr/share/php/Twig/Autoloader.php';
|
|
|
+Twig_Autoloader::register();
|
|
|
+$loader = new Twig_Loader_Filesystem('templates/');
|
|
|
+$twig = new Twig_Environment($loader, array(
|
|
|
+ 'cache' => '/tmp/',
|
|
|
+ 'auto_reload' => true
|
|
|
+ ));
|
|
|
+
|
|
|
+$sql = "";
|
|
|
+$rows = [];
|
|
|
+$columns = [];
|
|
|
+$loginSuccessfull = false;
|
|
|
+if (isset($_SESSION['user'])){
|
|
|
+ $loginSuccessfull = true;
|
|
|
+ $db = $_SESSION['db'];
|
|
|
+ $user = $_SESSION['user'];
|
|
|
+ $pw = $_SESSION['pw'];
|
|
|
+}
|
|
|
+else {
|
|
|
+ $db = "";
|
|
|
+ $user = "";
|
|
|
+ $pw = "";
|
|
|
+}
|
|
|
+$error = "";
|
|
|
+
|
|
|
+if (!$db && isset($_POST['login']) && isset($_POST['password']) && isset($_POST['database'])){
|
|
|
+ $db = $_POST['database'];
|
|
|
+ $user = $_POST['login'];
|
|
|
+ $pw = $_POST['password'];
|
|
|
+ try {
|
|
|
+ $dbh = new PDO("mysql:host=localhost;dbname=$db", $user, $pw);
|
|
|
+ $loginSuccessfull = true;
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ $error = $e->getMessage();
|
|
|
+ }
|
|
|
+}
|
|
|
+if (!$loginSuccessfull){
|
|
|
+ echo $twig->render('login.tpl', array("title" => "No PMA", "database" => $db, "login" => $user, "error" => $error));
|
|
|
+}
|
|
|
+else {
|
|
|
+ $_SESSION['db'] = $db;
|
|
|
+ $_SESSION['user'] = $user;
|
|
|
+ $_SESSION['pw'] = $pw;
|
|
|
+
|
|
|
+ $sql = isset($_POST['sql']) ? $_POST['sql'] : "";
|
|
|
+ $rowCount = false;
|
|
|
+
|
|
|
+ if ($sql){
|
|
|
+ try {
|
|
|
+ $dbh = new PDO("mysql:host=localhost;dbname=$db", $user, $pw);
|
|
|
+ $result = $dbh->query($sql);
|
|
|
+ $rows = $result->fetchAll();
|
|
|
+ if ($rows){
|
|
|
+ foreach (array_keys($rows[0]) as $column){
|
|
|
+ if (!is_numeric($column)){
|
|
|
+ $columns[] = $column;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ print_r($rows);
|
|
|
+ //print_r($columns);
|
|
|
+ $rowCount = $result->rowCount();
|
|
|
+ $dbh = null;
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ print "Error!: " . $e->getMessage() . "<br/>";
|
|
|
+ die();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ echo $twig->render('main.tpl', array("title" => "No PMA", "sql" => $sql, "rowCount" => $rowCount, "columns" => $columns, "rows" => $rows));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//print_r($_SESSION);
|