2007-07-09 07:29:02 +00:00
|
|
|
<?php
|
2025-03-05 11:28:53 +01:00
|
|
|
namespace Adminer;
|
|
|
|
|
|
2025-03-06 18:12:22 +01:00
|
|
|
$PROCEDURE = ($_GET["name"] ?: $_GET["call"]);
|
2009-08-29 13:57:50 +00:00
|
|
|
page_header(lang('Call') . ": " . h($PROCEDURE), $error);
|
2007-07-10 13:30:42 +00:00
|
|
|
|
2018-01-30 15:18:26 +01:00
|
|
|
$routine = routine($_GET["call"], (isset($_GET["callf"]) ? "FUNCTION" : "PROCEDURE"));
|
2007-07-09 16:11:34 +00:00
|
|
|
$in = array();
|
|
|
|
|
$out = array();
|
2007-07-16 13:52:46 +00:00
|
|
|
foreach ($routine["fields"] as $i => $field) {
|
2007-07-16 13:56:34 +00:00
|
|
|
if (substr($field["inout"], -3) == "OUT") {
|
2007-07-09 16:11:34 +00:00
|
|
|
$out[$i] = "@" . idf_escape($field["field"]) . " AS " . idf_escape($field["field"]);
|
|
|
|
|
}
|
2007-07-16 13:56:34 +00:00
|
|
|
if (!$field["inout"] || substr($field["inout"], 0, 2) == "IN") {
|
2007-07-09 16:11:34 +00:00
|
|
|
$in[] = $i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
|
2008-04-10 14:37:10 +00:00
|
|
|
if (!$error && $_POST) {
|
2007-07-09 16:11:34 +00:00
|
|
|
$call = array();
|
2007-07-16 13:52:46 +00:00
|
|
|
foreach ($routine["fields"] as $key => $field) {
|
2025-03-26 13:49:11 +01:00
|
|
|
$val = "";
|
2007-07-09 16:11:34 +00:00
|
|
|
if (in_array($key, $in)) {
|
2009-07-27 16:32:56 +00:00
|
|
|
$val = process_input($field);
|
2007-07-11 11:04:18 +00:00
|
|
|
if ($val === false) {
|
|
|
|
|
$val = "''";
|
|
|
|
|
}
|
2007-07-09 16:11:34 +00:00
|
|
|
if (isset($out[$key])) {
|
2009-09-22 10:51:40 +00:00
|
|
|
$connection->query("SET @" . idf_escape($field["field"]) . " = $val");
|
2007-07-09 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val);
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
2025-02-21 13:53:18 +01:00
|
|
|
|
2015-09-15 01:34:01 +03:00
|
|
|
$query = (isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . table($PROCEDURE) . "(" . implode(", ", $call) . ")";
|
2018-02-01 11:58:04 +01:00
|
|
|
$start = microtime(true);
|
|
|
|
|
$result = $connection->multi_query($query);
|
2024-11-08 21:48:25 +01:00
|
|
|
$affected = $connection->affected_rows; // getting warnings overwrites this
|
2018-02-01 13:12:05 +01:00
|
|
|
echo $adminer->selectQuery($query, $start, !$result);
|
2025-02-21 13:53:18 +01:00
|
|
|
|
2018-02-01 11:58:04 +01:00
|
|
|
if (!$result) {
|
2009-12-17 15:31:24 +00:00
|
|
|
echo "<p class='error'>" . error() . "\n";
|
2007-07-09 07:29:02 +00:00
|
|
|
} else {
|
2025-03-07 12:03:29 +01:00
|
|
|
$connection2 = connect($adminer->credentials());
|
2011-04-17 04:36:48 +02:00
|
|
|
if (is_object($connection2)) {
|
|
|
|
|
$connection2->select_db(DB);
|
|
|
|
|
}
|
2025-02-21 13:53:18 +01:00
|
|
|
|
2007-07-10 13:30:42 +00:00
|
|
|
do {
|
2009-09-22 10:51:40 +00:00
|
|
|
$result = $connection->store_result();
|
2007-07-10 13:30:42 +00:00
|
|
|
if (is_object($result)) {
|
2011-04-17 04:36:48 +02:00
|
|
|
select($result, $connection2);
|
2007-07-10 13:30:42 +00:00
|
|
|
} else {
|
2020-01-30 16:27:12 +01:00
|
|
|
echo "<p class='message'>" . lang('Routine has been called, %d row(s) affected.', $affected)
|
|
|
|
|
. " <span class='time'>" . @date("H:i:s") . "</span>\n" // @ - time zone may be not set
|
|
|
|
|
;
|
2007-07-10 13:30:42 +00:00
|
|
|
}
|
2009-09-22 10:51:40 +00:00
|
|
|
} while ($connection->next_result());
|
2025-02-21 13:53:18 +01:00
|
|
|
|
2007-07-09 16:11:34 +00:00
|
|
|
if ($out) {
|
2009-09-22 10:51:40 +00:00
|
|
|
select($connection->query("SELECT " . implode(", ", $out)));
|
2007-07-09 16:11:34 +00:00
|
|
|
}
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|
2007-07-09 16:11:34 +00:00
|
|
|
|
2007-07-09 07:29:02 +00:00
|
|
|
<form action="" method="post">
|
|
|
|
|
<?php
|
2007-07-09 16:11:34 +00:00
|
|
|
if ($in) {
|
2025-02-23 11:42:05 +01:00
|
|
|
echo "<table class='layout'>\n";
|
2007-07-09 16:11:34 +00:00
|
|
|
foreach ($in as $key) {
|
2007-07-16 13:52:46 +00:00
|
|
|
$field = $routine["fields"][$key];
|
2010-04-21 12:01:32 +00:00
|
|
|
$name = $field["field"];
|
2010-04-28 00:10:30 +00:00
|
|
|
echo "<tr><th>" . $adminer->fieldName($field);
|
2025-03-26 04:16:17 +01:00
|
|
|
$value = idx($_POST["fields"], $name);
|
2010-10-22 23:38:57 +02:00
|
|
|
if ($value != "") {
|
|
|
|
|
if ($field["type"] == "set") {
|
2025-03-10 23:32:28 +01:00
|
|
|
$value = implode(",", $value);
|
2010-10-22 23:38:57 +02:00
|
|
|
}
|
2007-07-09 16:11:34 +00:00
|
|
|
}
|
2025-03-26 04:16:17 +01:00
|
|
|
input($field, $value, idx($_POST["function"], $name, "")); // param name can be empty
|
2009-07-11 20:30:40 +00:00
|
|
|
echo "\n";
|
2007-07-09 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
echo "</table>\n";
|
|
|
|
|
}
|
|
|
|
|
?>
|
2007-07-11 21:06:19 +00:00
|
|
|
<p>
|
2009-07-11 20:30:40 +00:00
|
|
|
<input type="submit" value="<?php echo lang('Call'); ?>">
|
2025-03-17 18:45:08 +01:00
|
|
|
<?php echo input_token(); ?>
|
2007-07-09 07:29:02 +00:00
|
|
|
</form>
|
2025-02-23 16:35:11 +01:00
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
<?php
|
2025-03-26 21:06:01 +01:00
|
|
|
/** Format string as table row
|
|
|
|
|
* @param string
|
|
|
|
|
* @return string HTML
|
|
|
|
|
*/
|
2025-02-23 16:35:11 +01:00
|
|
|
function pre_tr($s) {
|
|
|
|
|
return preg_replace('~^~m', '<tr>', preg_replace('~\|~', '<td>', preg_replace('~\|$~m', "", rtrim($s))));
|
|
|
|
|
}
|
2025-03-26 21:06:01 +01:00
|
|
|
|
2025-02-23 17:04:43 +01:00
|
|
|
$table = '(\+--[-+]+\+\n)';
|
|
|
|
|
$row = '(\| .* \|\n)';
|
2025-03-05 16:32:51 +01:00
|
|
|
echo preg_replace_callback(
|
|
|
|
|
"~^$table?$row$table?($row*)$table?~m",
|
|
|
|
|
function ($match) {
|
2025-02-23 16:35:11 +01:00
|
|
|
$first_row = pre_tr($match[2]);
|
2025-02-23 17:04:43 +01:00
|
|
|
return "<table>\n" . ($match[1] ? "<thead>$first_row</thead>\n" : $first_row) . pre_tr($match[4]) . "\n</table>";
|
2025-02-23 16:35:11 +01:00
|
|
|
},
|
2025-03-05 09:14:49 +01:00
|
|
|
preg_replace(
|
|
|
|
|
'~(\n( -|mysql)> )(.+)~',
|
|
|
|
|
"\\1<code class='jush-sql'>\\3</code>",
|
|
|
|
|
preg_replace('~(.+)\n---+\n~', "<b>\\1</b>\n", h($routine['comment']))
|
2025-03-05 16:32:51 +01:00
|
|
|
)
|
|
|
|
|
);
|
2025-02-23 16:35:11 +01:00
|
|
|
?>
|
|
|
|
|
</pre>
|