Advertisement
Guest User

Untitled

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