sql.php: PDO support
This commit is contained in:
parent
17455af5f2
commit
c50aa4cd42
@ -187,6 +187,7 @@ class ShellListener:
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def interactive(self):
|
def interactive(self):
|
||||||
|
print("[ ] Switching to interactive mode")
|
||||||
self.on_message.append(lambda x: self.print_message(x))
|
self.on_message.append(lambda x: self.print_message(x))
|
||||||
while self.running and self.connection is not None:
|
while self.running and self.connection is not None:
|
||||||
self.sendline(input())
|
self.sendline(input())
|
||||||
|
45
sql.php
45
sql.php
@ -1,6 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
if (function_exists("mysqli_connect")) {
|
||||||
|
$db_driver = "mysqli";
|
||||||
|
} else if (class_exists("PDO")) {
|
||||||
|
$db_driver = "PDO";
|
||||||
|
} else {
|
||||||
|
die("Neither mysqli nor PDO could be found. Exiting.");
|
||||||
|
}
|
||||||
|
|
||||||
if (php_sapi_name() === "cli") {
|
if (php_sapi_name() === "cli") {
|
||||||
$username = $argv[1];
|
$username = $argv[1];
|
||||||
@ -18,37 +25,67 @@ if (php_sapi_name() === "cli") {
|
|||||||
$dump_all = isset($_REQUEST["dumpAll"]);
|
$dump_all = isset($_REQUEST["dumpAll"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($db_driver === "mysqli") {
|
||||||
$link = mysqli_connect($host, $username, $password, $database);
|
$link = mysqli_connect($host, $username, $password, $database);
|
||||||
if (!$link) {
|
if (!$link) {
|
||||||
die("Error connecting to mysql: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")");
|
die("Error connecting to mysql: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")");
|
||||||
}
|
}
|
||||||
|
} else if ($db_driver === "PDO") {
|
||||||
|
$databaseStr = $database ? ";dbname=$database" : "";
|
||||||
|
$link = new PDO("mysql:host=$host$databaseStr", $username, $password);
|
||||||
|
$link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
}
|
||||||
|
|
||||||
if ($dump_all) {
|
if ($dump_all) {
|
||||||
$res = mysqli_query($link, "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='$database'");
|
|
||||||
$tables = array();
|
$tables = array();
|
||||||
|
|
||||||
|
if ($db_driver === "mysqli") {
|
||||||
|
$res = mysqli_query($link, "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='$database'");
|
||||||
while ($row = $res->fetch_assoc()) {
|
while ($row = $res->fetch_assoc()) {
|
||||||
$tables[] = $row["TABLE_NAME"];
|
$tables[] = $row["TABLE_NAME"];
|
||||||
}
|
}
|
||||||
|
} else if ($db_driver === "PDO") {
|
||||||
|
$stmt = $link->query("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='$database'");
|
||||||
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
$tables[] = $row["TABLE_NAME"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($tables as $tableName) {
|
foreach ($tables as $tableName) {
|
||||||
echo "-- DATA FOR TABLE: tableName\n";
|
echo "-- DATA FOR TABLE: tableName\n";
|
||||||
|
if ($db_driver === "mysqli") {
|
||||||
$res = mysqli_query($link, "SELECT * FROM $tableName");
|
$res = mysqli_query($link, "SELECT * FROM $tableName");
|
||||||
while ($row = $res->fetch_assoc()) {
|
while ($row = $res->fetch_assoc()) {
|
||||||
var_dump($row);
|
print_r($row);
|
||||||
|
}
|
||||||
|
} else if ($db_driver === "PDO") {
|
||||||
|
$stmt = $link->query("SELECT * FROM $tableName");
|
||||||
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
print_r($row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo "-- --------------------------\n\n";
|
echo "-- --------------------------\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if ($db_driver === "mysqli") {
|
||||||
$res = mysqli_query($link, $query);
|
$res = mysqli_query($link, $query);
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
die("Error executing query: " . mysqli_error($link));
|
die("Error executing query: " . mysqli_error($link));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while ($row = $res->fetch_assoc()) {
|
while ($row = $res->fetch_assoc()) {
|
||||||
var_dump($row);
|
print_r($row);
|
||||||
|
}
|
||||||
|
} else if ($db_driver === "PDO") {
|
||||||
|
$stmt = $link->query($query);
|
||||||
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
print_r($row);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($db_driver === "mysqli") {
|
||||||
mysqli_close($link);
|
mysqli_close($link);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user