-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_query.php
More file actions
51 lines (44 loc) · 1.34 KB
/
run_query.php
File metadata and controls
51 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
// Connect database
include('connectdb.php');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['custom_query'])) {
$sql = trim($_POST['custom_query']);
if (substr($sql, -1) === ';') {
$sql = rtrim($sql, ';');
}
$stid = oci_parse($conn, $sql);
$result = oci_execute($stid);
if ($result) {
echo "<h3>Results for Query:</h3>";
echo "<table border='1'>";
$ncols = oci_num_fields($stid);
// Print table headers
echo "<tr>";
for ($i = 1; $i <= $ncols; $i++) {
$colname = oci_field_name($stid, $i);
echo "<th>" . htmlspecialchars($colname, ENT_QUOTES | ENT_HTML5) . "</th>";
}
echo "</tr>";
// Print table rows
while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {
echo "<tr>";
foreach ($row as $item) {
echo "<td>" . ($item !== null ? htmlspecialchars($item, ENT_QUOTES | ENT_HTML5) : " ") . "</td>";
}
echo "</tr>";
}
echo "</table><br>";
} else {
$error = oci_error($stid);
echo "Error executing query: " . $error['message'] . "<br>";
}
}
}
// Close the connection
if ($conn) {
oci_close($conn);
}
?>