Advertisement
Guest User

Untitled

a guest
May 18th, 2017
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.01 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Universal SQL connector 0.3.2
  4.  *
  5.  * @author mario
  6.  */
  7. $host       = 'localhost';
  8. $db         = 'XXXXXX';
  9. $username   = 'XXXXXX';
  10. $password   = 'XXXXXX';
  11.  
  12. $json_output = array();
  13.  
  14. isset($_REQUEST['json']) ? ob_start() : null;
  15.  
  16. $_REQUEST['query'] = utf8_decode($_REQUEST['query']);
  17.  
  18. error_reporting(1);
  19. ?>
  20. <!doctype html><meta charset="UTF-8" />
  21. <style>
  22.     *{font-size:12px;margin:0}body{padding:5px}input{width:100%;height:30px}p{padding:5px;border:1px solid #666}
  23.     textarea{width:99%;height:100px;padding:5px;border:#fff}span{display:block;padding:5px}h5{padding:5px}
  24.     .success{background:#C9FFC9}.fail{background:#FFC9C9}form{margin-bottom:10px}
  25. </style>
  26. <title>Universal SQL connector 0.3.2</title>
  27. <form><fieldset><textarea name="query"><?php
  28. echo isset($_REQUEST['query']) ? htmlentities($_REQUEST['query']) : 'SELECT "hello"';
  29. ?></textarea></fieldset><input type="submit" value="Submit Query" /></form>
  30.  
  31. <?php if(isset($_REQUEST['query']) && $_REQUEST['query']) { ?>
  32.     <?php
  33.         $fp = fopen('usclog.txt', 'a');
  34.         $log_entry = rawurlencode($_REQUEST['query']).' ' . date('Y-m-d H:i:s') . ' ' . $_SERVER['REMOTE_ADDR'] ."\r\n";
  35.         fwrite($fp, $log_entry);
  36.         //mail('mario.heiderich@gmail.com', '[info] USC Activity', $log_entry)
  37.     ?>
  38.     <h5>MySQL</h5>
  39.     <p>
  40.     <?php
  41.         $link = mysql_connect($host, $username, $password);
  42.         mysql_select_db($db,$link);
  43.        
  44.         if($res = mysql_query($_REQUEST['query'], $link)) {
  45.             echo '<span class="success">';
  46.             $json_output['mysql_connect'] = $output = mysql_fetch_assoc($res);
  47.             foreach($output as $key => $value) {
  48.                 echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  49.             }          
  50.         } else {
  51.             echo '<span class="fail">';
  52.             echo htmlentities(mysql_error());  
  53.         }
  54.         echo '</span>';
  55.     ?>
  56.     </p><h5>Mysqli</h5><p>
  57.     <?php
  58.         $link = new mysqli($host, $username, $password, $db);
  59.         if($res = $link->query($_REQUEST['query'])) {
  60.             echo '<span class="success">';
  61.             $json_output['mysqli'] = $output = $res->fetch_assoc();
  62.             foreach($output as $key => $value) {
  63.                 echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  64.             }  
  65.         } else {
  66.             echo '<span class="fail">';
  67.             echo htmlentities($link->error);   
  68.         }
  69.         echo '</span>';
  70.     ?>
  71.     </p><h5>PDO (MySQL)</h5><p>
  72.     <?php
  73.         $link = new PDO('mysql:host='.$host.';port=3306;dbname='.$db, $username, $password);
  74.         if($res = $link->query($_REQUEST['query'])) {
  75.             echo '<span class="success">';
  76.             foreach($res as $row) {
  77.                 $json_output['pdo'] = $output = $row;
  78.                 foreach($row as $key => $value) {
  79.                     echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  80.                 }              
  81.             }  
  82.         } else {
  83.             echo '<span class="fail">';
  84.             $pdo_error = $link->errorInfo();
  85.             echo htmlentities($pdo_error[2]);
  86.         }
  87.         echo '</span>';
  88.     ?>
  89.     </p><h5>ODBC (MySQL)</h5><p>
  90.     <?php
  91.         $link = odbc_connect('DRIVER={MySQL ODBC 3.51 Driver};Server=localhost;Database='.$db, $username, $password);
  92.         if($res = odbc_exec($link, $_REQUEST['query'])) {
  93.             echo '<span class="success">';
  94.             $json_output['pdo'] = $output = odbc_fetch_array($res);
  95.             foreach($output as $key => $value) {
  96.                 echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  97.             }              
  98.         } else {
  99.             echo '<span class="fail">';
  100.             echo htmlentities(odbc_errormsg());
  101.         }
  102.         echo '</span>';
  103.     ?>
  104.     </p>
  105.     <h5>SQLite</h5>
  106.     <p>
  107.     <?php
  108.         $link = sqlite_open('test');
  109.         if($res = sqlite_query($link, $_REQUEST['query'])) {
  110.             echo '<span class="success">';
  111.             $json_output['sqlite'] = $output = sqlite_fetch_array($res);
  112.             foreach($output as $key => $value) {
  113.                 echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  114.             }          
  115.         } else {
  116.             echo '<span class="fail">';
  117.             echo htmlentities(sqlite_error_string(sqlite_last_error($link)));  
  118.         }
  119.         echo '</span>';
  120.     ?>
  121.     </p>
  122.     <h5>PostgreSQL</h5>
  123.     <p>
  124.     <?php
  125.         $link = pg_connect('host='.$host.' port=5432 dbname=postgres user=postgres password='.$password);
  126.         if($res = pg_query($link, $_REQUEST['query'])) {
  127.             echo '<span class="success">';
  128.             $json_output['pg_connect'] = $output = pg_fetch_assoc($res);
  129.             foreach($output as $key => $value) {
  130.                 echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  131.             }              
  132.         } else {
  133.             echo '<span class="fail">';
  134.             echo htmlentities(utf8_decode(pg_last_error()));   
  135.         }
  136.         echo '</span>';
  137.     ?>
  138.     </p>
  139.     <h5>Oracle XE</h5>
  140.     <p>
  141.     <?php
  142.         $link = oci_connect($username, $password, $host);
  143.         $statement = oci_parse($link, $_REQUEST['query']);
  144.         if(oci_execute($statement)) {
  145.             echo '<span class="success">';
  146.             $json_output['oci_connect'] = $output = oci_fetch_assoc($statement);
  147.             foreach($output as $key => $value) {
  148.                 echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  149.             }              
  150.         } else {
  151.             echo '<span class="fail">';
  152.             $oci_error = oci_error($statement);
  153.             echo htmlentities($oci_error['message']);  
  154.         }
  155.         echo '</span>';
  156.     ?>
  157.     </p>
  158.     <h5>Firebird</h5>
  159.     <p>
  160.     <?php
  161.         $link = ibase_connect($host.':'.dirname(__FILE__).'/test.gdb', $username, $password);
  162.         if($res = ibase_query($link, $_REQUEST['query'])) {
  163.             echo '<span class="success">';
  164.             $json_output['ibase_connect'] = $output = ibase_fetch_assoc($res);
  165.             foreach($output as $key => $value) {
  166.                 echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';    
  167.             }              
  168.         } else {
  169.             echo '<span class="fail">';
  170.             echo htmlentities(ibase_errmsg()); 
  171.         }
  172.         echo '</span>';
  173.     ?>
  174.     </p>   
  175.     <br />
  176.     <p>
  177.         <a href="?query=<?php echo urlencode($_REQUEST['query']) ?>&json">Show result as JSON</a>
  178.     </p>   
  179. <?php } ?>
  180. <br />
  181. <p>
  182.     Welcome to the Universal SQL connector tool. You can fire arbitrary
  183.     SELECT queries against several DBMS using several connectors including:
  184.     <br />
  185.     MySQL (mysql, mysqli, PDO, ODBC), SQLite, PostgreSQL, Firebird and Oracle
  186.     <br />
  187.     <small><a href="mailto:mario.heiderich@gmail.com">mario.heiderich@gmail.com</small>
  188. </p>
  189. <?php
  190.     if(isset($_REQUEST['json'])) {
  191.         ob_clean();
  192.         echo json_encode($json_output);
  193.     } else {
  194.         ob_flush();
  195.     }
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement