Error: Could not write {$file}";
}
} */
// Open the queries.txt file and read each line
/*if (file_exists($file)) {
$queries = file($file, FILE_IGNORE_NEW_LINES); // Read lines into an array
foreach ($queries as $query) {
// Create a link for each query in the file
echo '
";
}
*/
if (file_exists($file)) {
$queries = file($file, FILE_IGNORE_NEW_LINES); // Read lines into an array
echo '';
} else {
echo "
{$file} file not found.
";
}
?>
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 "
";
}
}
}
/*
// 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 "