Execute Query



Available Queries

getConnection(); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $query = $_POST['query']; // Get the query from the text area // Split the query if multiple queries are entered $queries = explode(';', $query); // Process each query foreach ($queries as $sql) { $sql = trim($sql); // Remove extra spaces echo $sql; echo "

\n"; if ($sql) { $result = $conn->query($sql); print_r($result); if ($result === FALSE) { echo "

Error: " . $conn->error . "

"; } elseif ($result === TRUE) { echo "

Query executed successfully.

"; } else { // If it's a SELECT query, display results in a table echo ""; // Display table headers $fields = $result->fetch_fields(); foreach ($fields as $field) { echo ""; } echo ""; // Display rows while ($row = $result->fetch_assoc()) { echo ""; foreach ($row as $value) { //echo ""; echo ""; } echo ""; } echo "
" . $field->name . "
" . htmlspecialchars($value) . "" . $value . "


"; } } } /* // Now let's append the query to queries.txt if it's not already there $queries = file($file, FILE_IGNORE_NEW_LINES); // Read the existing queries into an array if (!in_array($query, $queries)) { $queries[] = $query; // Add the new query to the array sort($queries); // Sort the queries alphabetically file_put_contents($file, implode(PHP_EOL, $queries) . PHP_EOL); // Save the sorted queries back to the file //echo "

Query added to queries.txt.

"; } else { echo ""; //echo "

Query already exists in queries.txt.

"; } */ $conn->close(); } ?>