Skip to content

Instantly share code, notes, and snippets.

@timsheu
Last active May 10, 2018 14:29
Show Gist options
  • Select an option

  • Save timsheu/1c78782c285963aaa73c7763bac8dc18 to your computer and use it in GitHub Desktop.

Select an option

Save timsheu/1c78782c285963aaa73c7763bac8dc18 to your computer and use it in GitHub Desktop.
query.php
# Tested with browser command:
# http://127.0.0.1/query.php?ipAddress=127.0.0.1&dbLogin=root&dbPassword=48694062&dbName=SURLMICE_TWEET_apple&sqlCommand=SHOW%20TABLES
# Result
# [{"Tables_in_surlmice_tweet_apple":"2013_07_07"},{"Tables_in_surlmice_tweet_apple":"2014_05_28"},{"Tables_in_surlmice_tweet_apple":"2016_04_28"}]
<?php
$ip_address = $_REQUEST['ipAddress'];
$db_login = $_REQUEST['dbLogin'];
$db_pass = $_REQUEST['dbPassword'];
$db_name = $_REQUEST['dbName'];
$sql_command = $_REQUEST['sqlCommand'];
$db = mysqli_connect($ip_address, $db_login, $db_pass, $db_name);
#Local test
#$db = mysqli_connect("127.0.0.1", "root", "48694062", "SURLMICE_TWEET_apple");
#mysqli_select_db($db, "SURLMICE_TWEET_apple");
$result = mysqli_query($db, $sql_command);
#No parameter test
#$result = mysqli_query($db, "SELECT * FROM `2016_04_28` WHERE 1");
#$result = mysqli_query($db, "SHOW TABLES");
while ($r = mysqli_fetch_assoc($result)) {
$output[] = $r;
}
print(json_encode($output));
mysqli_close($db);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment