Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Universal SQL connector 0.3.1
- */
- $host = 'localhost';
- $db = 'XXXXXX';
- $username = 'XXXXXX';
- $password = 'XXXXXX';
- $json_output = array();
- isset($_REQUEST['json']) ? ob_start() : null;
- error_reporting(1);
- ?>
- <!doctype html><meta charset="UTF-8" />
- <style>
- *{font-size:12px;margin:0}body{padding:5px}input{width:100%;height:30px}p{padding:5px;border:1px solid #666}
- textarea{width:99%;height:100px;padding:5px;border:#fff}span{display:block;padding:5px}h5{padding:5px}
- .success{background:#C9FFC9}.fail{background:#FFC9C9}form{margin-bottom:10px}
- </style>
- <title>Universal SQL connector 0.3.1</title>
- <form><fieldset><textarea name="query"><?php
- echo isset($_REQUEST['query']) ? htmlentities($_REQUEST['query']) : 'SELECT "hello"';
- ?></textarea></fieldset><input type="submit" value="Submit Query" /></form>
- <?php if(isset($_REQUEST['query']) && $_REQUEST['query']) { ?>
- <?php
- $fp = fopen('usclog.txt', 'a');
- $log_entry = rawurlencode($_REQUEST['query']).' ' . date('Y-m-d H:i:s') . ' ' . $_SERVER['REMOTE_ADDR'] ."\r\n";
- fwrite($fp, $log_entry);
- ?>
- <h5>MySQL</h5>
- <p>
- <?php
- $link = mysql_connect($host, $username, $password);
- mysql_select_db($db,$link);
- if($res = mysql_query($_REQUEST['query'], $link)) {
- echo '<span class="success">';
- $json_output['mysql_connect'] = $output = mysql_fetch_assoc($res);
- foreach($output as $key => $value) {
- echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';
- }
- } else {
- echo '<span class="fail">';
- echo htmlentities(mysql_error());
- }
- echo '</span>';
- ?>
- </p><h5>Mysqli</h5><p>
- <?php
- $link = new mysqli($host, $username, $password, $db);
- if($res = $link->query($_REQUEST['query'])) {
- echo '<span class="success">';
- $json_output['mysqli'] = $output = $res->fetch_assoc();
- foreach($output as $key => $value) {
- echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';
- }
- } else {
- echo '<span class="fail">';
- echo htmlentities($link->error);
- }
- echo '</span>';
- ?>
- </p><h5>PDO (MySQL)</h5><p>
- <?php
- $link = new PDO('mysql:host='.$host.';port=3306;dbname='.$db, $username, $password);
- if($res = $link->query($_REQUEST['query'])) {
- echo '<span class="success">';
- foreach($res as $row) {
- $json_output['pdo'] = $output = $row;
- foreach($row as $key => $value) {
- echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';
- }
- }
- } else {
- echo '<span class="fail">';
- $pdo_error = $link->errorInfo();
- echo htmlentities($pdo_error[2]);
- }
- echo '</span>';
- ?>
- </p><h5>ODBC (MySQL)</h5><p>
- <?php
- $link = odbc_connect('DRIVER={MySQL ODBC 3.51 Driver};Server=localhost;Database='.$db, $username, $password);
- if($res = odbc_exec($link, $_REQUEST['query'])) {
- echo '<span class="success">';
- $json_output['pdo'] = $output = odbc_fetch_array($res);
- foreach($output as $key => $value) {
- echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';
- }
- } else {
- echo '<span class="fail">';
- echo htmlentities(odbc_errormsg());
- }
- echo '</span>';
- ?>
- </p>
- <h5>SQLite</h5>
- <p>
- <?php
- $link = sqlite_open('test');
- if($res = sqlite_query($link, $_REQUEST['query'])) {
- echo '<span class="success">';
- $json_output['sqlite'] = $output = sqlite_fetch_array($res);
- foreach($output as $key => $value) {
- echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';
- }
- } else {
- echo '<span class="fail">';
- echo htmlentities(sqlite_error_string(sqlite_last_error($link)));
- }
- echo '</span>';
- ?>
- </p>
- <h5>PostgreSQL</h5>
- <p>
- <?php
- $link = pg_connect('host='.$host.' port=5432 dbname=postgres user=postgres password='.$password);
- if($res = pg_query($link, $_REQUEST['query'])) {
- echo '<span class="success">';
- $json_output['pg_connect'] = $output = pg_fetch_assoc($res);
- foreach($output as $key => $value) {
- echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';
- }
- } else {
- echo '<span class="fail">';
- echo htmlentities(pg_last_error());
- }
- echo '</span>';
- ?>
- </p>
- <h5>Oracle XE</h5>
- <p>
- <?php
- $link = oci_connect($username, $password, $host);
- $statement = oci_parse($link, $_REQUEST['query']);
- if(oci_execute($statement)) {
- echo '<span class="success">';
- $json_output['oci_connect'] = $output = oci_fetch_assoc($statement);
- foreach($output as $key => $value) {
- echo '['.htmlentities($key) . '] => ' . htmlentities($value) . '<br />';
- }
- } else {
- echo '<span class="fail">';
- $oci_error = oci_error($statement);
- echo htmlentities($oci_error['message']);
- }
- echo '</span>';
- ?>
- </p>
- <br />
- <p>
- <a href="?query=<?php echo urlencode($_REQUEST['query']) ?>&json">Show result as JSON</a>
- </p>
- <?php } ?>
- <br />
- <p>
- Welcome to the Universal SQL connector tool. You can fire arbitrary
- SELECT queries against several DBMS using several connectors including:
- <br />
- MySQL (mysql, mysqli, PDO, ODBC), SQLite and PostgreSQL
- <br />
- </p>
- <?php
- if(isset($_REQUEST['json'])) {
- ob_clean();
- echo json_encode($json_output);
- } else {
- ob_flush();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement