les commentaires dans l'historique sont en gras
[bazdig.git] / bazdig / sql / exec / index.php
blob248bd19fe8bd1825b1c892731cb3d7fbffbd58c3
1 <?php
2 session_start();
4 define('WARAQ_ROOT', '../../..');
5 require_once WARAQ_ROOT .'/'. 'ini.php';
7 require "code.php";
9 if ($_GET['dbt']) {
10 $_SESSION['db_type'] = $_GET['dbt'];
11 $_SESSION['db_name'] = $_GET['dbn'];
12 $_SESSION['db_host'] = $_GET['dbh'];
13 $_SESSION['db_user'] = $_GET['dbu'];
14 $_SESSION['db_password'] = $_GET['dbp'];
17 if (!$_SESSION['db_type'] or !$_GET['q']) {
18 header('Location: '. $bazdig->get('/console')->url );
21 $history_db = new PDO("sqlite:". $bazdig->getparam('db')->file);
22 $work_db = new BDB(array('type' => $_SESSION['db_type'], 'name' => $_SESSION['db_name'], 'host' => $_SESSION['db_host']), $_SESSION['db_user'], $_SESSION['db_password']);
24 SqlCode::set_db($history_db);
25 $query = new SqlCode(stripslashes($_GET['q']));
27 <html>
28 <head>
29 <style type="text/css">
30 table tr td {border: solid 1px silver; padding: 10px}
31 table tr th {border: solid 1px grey; padding: 10px}
32 #error {
33 background-color: yellow;
34 border: 2px solid red;
35 padding: 10px;
36 margin: 10px;
38 </style>
39 <?php
40 try {
41 $result = $query->exec($work_db);
42 } catch (Exception $e) {
43 die("<div id='error'><b>SQL ERROR</b> ". $e->getMessage() ."</div>");
46 $query->save();
48 try {
49 $rows = $result->fetchAll(PDO::FETCH_ASSOC);
50 if (count($rows) < 1) {
51 die("<table><tr><th>Empty</th></tr></table>");
53 } catch (Exception $e) {
54 die("<table><tr><th>Empty</th></tr></table>");
56 $columns = columnNames($rows[0]);
59 <title><?php echo join($columns, ' '); ?></title>
60 </head>
61 <body>
62 <?php
63 echo "<table><tr>";
64 foreach ($columns as $c) {
65 echo "<th>$c</th>";
67 echo "</tr>";
68 foreach ($rows as $r) {
69 echo "<tr>";
70 foreach ($r as $value) {
71 echo "<td>$value</td>";
73 echo "</tr>";
75 echo "</table>";
77 </body>
78 </html>